Nitay Nitay - 2 years ago 497
Python Question

dpkt throws NeedData on valid pcap

I have this python code:

import sys
import dpkt

f = file("pcaop.Pcap")
pcap = dpkt.pcap.Reader(f)

i = 0
for ts, buf in pcap:
print "Ya"

dpkt throws NeedData on the 52nd packet. The same one every time - I've checked packet 52 and it is the same as everyone else on wireshark.

What causes this?

Answer Source

Solution is provided here: Python stops reading file using read I had the same problem when dpkt.pcap was working fine under Linux but failed instantly when run in Windows. The problem is that when a file is opened in text mode open("filename", "r") the file is read until EOF is encountered. Thus, open("filename", "rb")

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download