In this code with pyshark
import pyshark
cap = pyshark.FileCapture(filename)
i = 0
for idx, packet in enumerate(cap):
i += 1
print i
print len(cap._packets)
i and len(cap._packets) give two different results. Why is that?
In this code with pyshark
import pyshark
cap = pyshark.FileCapture(filename)
i = 0
for idx, packet in enumerate(cap):
i += 1
print i
print len(cap._packets)
i and len(cap._packets) give two different results. Why is that?
A look at the source code reveals that
_packetsis a list containing packets and is only used internally:When iterating through a
FileCaptureobject withkeep_packets = Truepackets are getting added to this list.To get access to all packets in a
FileCaptureobject you should iterate over it just like you did:But to count the amount of packets just do this:
or use a counter like you did, but don't use
_packetsas it does not contain the complete packet list.