I'm doing an assignment where I have to parse through a pcap file and I am using dpkt to do so. I'm new to networking so I'm having a really hard time debugging the code / getting started.
First set of code:
import dpkt
filename='test.pcap'
f = open(filename)
pcap = dpkt.pcap.Reader(f)
for ts, buf in pcap:
eth = dpkt.ethernet.Ethernet(buf)
ip = eth.data
tcp = ip.data
f.close()
Error is AttributeError: 'str' object has no attribute 'data'
So from a previous Stackoverflow I found out that maybe I'm supposed to "skip the dpkt ethernet decode and jump straight to an IP decode" so I altered the code and go to:
import dpkt
filename='test.pcap'
f = open(filename)
pcap = dpkt.pcap.Reader(f)
for ts,buf in pcap:
ip = dpkt.ip.IP(buf)
tcp = ip.data
f.close()
The error it is giving me now is "UnpackError: invalid header length"
Don't really understand how to move forward with this, any help would be greatly appreciated