This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Print number of tcp flows

0

I know that by doing

tshark -r pcap.pcap -qz conv,tcp

I can read all the TCP flows but I would like to see specifically the number of flows that exist on a pcap file. I do not want to do that through wc -l because I am not sure if the output is always similar and whether additional lines will be added.

asked 28 Jan '16, 07:55

altdrugzgene's gravatar image

altdrugzgene
11448
accept rate: 0%


One Answer:

1

Maybe use the fields option and directly output the tcp.stream field, then post-process that to find the highest unique value, e.g. using PowerShell:

tshark -r pcap.pcap -T fields -e tcp.stream | foreach{ [int]$_ + 1 } | SortObject -Unique -Descending | Select-Object -First 1

Basically sort the stream integers into descending order, omitting duplicates, then select the first 1 (or head).

Note that this will give a 0-based index of the streams, to get the actual stream count you still have to add 1.

Update: Added coercion to int to fix numeric sort, plus an offset to make the numbers 1 based and the resulting count accurate.

answered 28 Jan '16, 08:15

grahamb's gravatar image

grahamb ♦
19.8k330206
accept rate: 22%

edited 28 Jan '16, 09:47

Thanks for your reply. Interestingly from the first piece tshark -r pcap.pcap -T fields -e tcp.stream I am getting 53 as the largest however I noticed that there are 54 flows! Is it starting counting from 0 ? I am using linux btw so no powershell for me! :P

(28 Jan '16, 08:29) altdrugzgene

Note the last bit of my answer about the stream field being 0-based.

In bash you should be able to run ... | sort -ur | head -1

(28 Jan '16, 08:46) grahamb ♦

This returns totally wrong number.. dunno why

(28 Jan '16, 08:58) altdrugzgene

Add -g to the sort parms to make it a numeric sort?

(28 Jan '16, 09:20) grahamb ♦

sweet that worked.. still have to get the first entry with -g though. I thought it would be possible to get it from tshark itself but ok. Cheers and Thanks

(28 Jan '16, 09:27) altdrugzgene