KimiNewt / pyshark

Python wrapper for tshark, allowing python packet parsing using wireshark dissectors
MIT License
2.18k stars 419 forks source link

How to get number of packets in capture? #483

Open plipK opened 3 years ago

plipK commented 3 years ago

I tried

capture = pyshark.FileCapture(capFile)
numPackets = len(capture)

but that returns 0.

Kesslerb2 commented 3 years ago
        cap = pyshark.FileCapture(capFile)
        print(len(cap))

        cap.load_packets()
        print(len(cap))

Should output 0 for the first len call and the actual number of packets for the second.

joergdeutschmann-i7 commented 1 year ago

With a ~12 Mbyte pcap file, cap.load_packets() needs roughly 5 Gbyte of RAM on my computer. So maybe it is not suitable for very large files?

I've simply iterated with a separate counter to avoid high memory usage...

counter = 0
for packet in cap:
    counter += 0
print(counter)