Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to do an analysis on pcap files, but tshark seems rather heavy for the simple analysis I want, such as:

  • number of packets
  • capture duration
  • total bytes

Is there an easier way to get these statistics?

share|improve this question

Using lovely python in a lazy way:

# apt-get install python-pypcap

>>> import pcap
>>> p = pcap.pcap(name="hs22v-boot.pcap")
>>> packets = [x for x in p]
>>> duration = packets[-1][0] - packets[0][0]
>>> totalbytes = sum([len(x[1]) for x in packets])
>>> numpackets = len(packets)
>>> duration, totalbytes, numpackets
(113.37264108657837, 193812281, 227491)
share|improve this answer
Turning this into properly efficient code is left as an exercise for the reader. – MikeyB Jul 25 '12 at 15:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.