Search code examples
csvwiresharkpcaptshark

CSV output file using command line for wireshark IO graph statistics


I save the IO graph statistics as CSV file containing the bits per second using the wireshark GUI. Is there a way to generate this CSV file with command line tshark? I can generate the statistics on command line as bytes per second as follows

tshark -nr test.pcap -q -z io,stat,1,BYTES

How do I generate bits/second and save it to a CSV file?

Any help is appreciated.


Solution

  • I don't know a way to do that using only tshark, but you can easily parse the output from tshark into a CSV file:

    tshark -nr tmp.pcap -q -z io,stat,1,BYTES | grep -P "\d+\s+<>\s+\d+\s*\|\s+\d+" | awk -F '[ |]+' '{print $2","($5*8)}'
    

    Explanations

    • grep -P "\d+\s+<>\s+\d+\s*\|\s+\d+" selects only the raw from the tshark output with the actual data (i.e., second <> second | transmitted bytes).
    • awk -F '[ |]+' '{print $2","($5*8)}' splits that data into 5 blocks with [ |]+ as the separator and display blocks 2 (the second at which starts the interval) and 5 (the transmitted bytes) with a comma between them.