I would like to save the output of a tshark
command in a variable.
For example if I run:
tshark -r capture.pcap -qz io,stat,0
I will get :
Time |frames| bytes
00.000-060.000 742 51660
I want to save the total number of frames in a variable in my script for further calculations.
On my system
tshark
's output format differs from the one you've shown in the question. To make parsing more robust, I've changed the command-line:You don't need to call
tshark
to get statistics from a pcap file. You could use a Python library that can parse pcap files e.g., usingscapy
:To get count for
tshark -r capture.pcap -qz 'io,stat,0,ip.src==192.168.230.146'
command usingscapy
:First save the output to a file :
Either by running this command in shell:
tshark -r capture.pcap -qz io,stat,0 > abc.txt
:Or use
subprocess.Popen()
:Now open the file and calculate the total number of frames: