Dear All, I want to split captured traffic based on the delay between packet. so that if the the delay between two packet is more than the threshold, save the trace in new file. How can I do it using tshark commands? Edit1: here is the code I use for splitting traffic based on Sindy's answer:
And use Sindy's MATE configuration with just changing the delay time. But while loop didn't stop. should I use other option to check whether .pcapng file is empty or not? asked 02 Sep '16, 15:00 Zahra edited 05 Sep '16, 06:40 sindy |
One Answer:
If I get you right and you want to create a new file each time the pause between packets is longer than the threshold, it cannot be done while capturing. MATE could be a way to mark all frames belonging to the same "burst" with a unique numeric ID ( An example of MATE configuration with a gap threshold of 0.01 second follows:
answered 03 Sep ‘16, 02:35 sindy edited 03 Sep ‘16, 23:54 showing 5 of 10 show 5 more comments |
Thanks for your reply, I want to do it after capturing, while reading traffic using -r and other filtering options in my processing phase. Is there other solution?
Well, I’ve already described the suggestion as only applicable in the post-processing mode, so I’m not sure whether I get your reaction properly.
If you want to split the capture into parts up to the gaps between frames only after applying your display filter, I’m afraid you would have to use two instances of tshark in a chain. Tshark does support an idea of a separate “read filter” and “display filter” which use the same syntax but serve a different purpose, yet the two-pass mode of tshark which is currently mandatory for use of read filter has some trouble with MATE. But you may give it a try:
If it does not work, you have to revert to the chain method:
But it may not be possible on Windows.
Sorry I didn’t try MATE before, how should I add MATE configuration to my bash script. In https://wiki.wireshark.org/Mate/GettingStarted wasn’t any explanation for do it in ubuntu and also in bash script. Could you plz help me in this?
tshark shares a common preferences file with Wireshark, so you can use Wireshark’s GUI to set the MATE configuration file. But you can use
-o preference:value
to override any of the values stored in the preferences file, so for our case, it would be-o mate.config:/full/path/to/your/mate/config/file
thanks, now tshark works fine, but there is a problem about check file is empty or not?
The thing is that for a pcap or pcapng file, “empty” means “contains no frames”, not “has zero size”, so
-s filename
returns true even for empty files. The reason is that tshark creates the file and writes the header into it right at start, not as late as when writing the first frame. For pcap, the size of an empty file is 24 bytes; for pcapng, it is128 bytesvariable depending on the environment.Google of “file size bash” returns links to several Q&A sites with sophisticated answers; I would myself use
wc -c < filename
. So the whole replacement ofif [ -s capture/flows/${nbase}/mainflow/${base}$id.pcapng ] ;
in your script would beif (($(wc -c < capture/flows/${nbase}/mainflow/${base}$id.pcapng)>128)) ;
in my case empty pcapng file is 380, is there any differences by case?
I haven’t analysed it deeply, but it depends on what tshark writes to the file at start. If the interface description(s) are written, the resulting size depends on the interface name(s) which are strings whose size depends on the environment. Just for the fun of it, can you post your empty pcapng file?
It seems that tshark has no option allowing to easily evaluate emptiness of a file, nor the manual says anything about a return code.
So to make the script portable, you may have to use a never matching display filter like
-Y “eth and !eth”
to generate an output file which is surely empty and use its size as a reference for the comparison.thanks, here is my empty .pcapng file. http://s000.tinyupload.com/?file_id=03339871074200476632
OK, so the size of an “empty” pcapng really depends on a lot of factors, not just on the environment where tshark runs.
in my case, there is just the signature of the application which has created it, which was tshark because the input file was a pcap one, not a pcapng one.
in your case, the original creator of the pcapng was dumpcap, so on top of its signature, there is also an interface description and capture filter because tshark has copied all this information from the input file to the output one.