I have configured a Cisco router to dump a pcap file for traffic on a specific interface that I am trying to parse with dpkt and Python (2.7). The basic code is:
f = open('pktrace1.pcap','rb')
pcap = dpkt.pcap.Reader(f)
for ts,buf in pcap:
eth = dpkt.ethernet.Ethernet(buf)
ip = eth.data
tcp = ip.data
f.close()
Now unfortunately for whatever reason the pcap dumps from the router leave the layer 2 information blank and the frame is encapsulated in a raw IP format. The above code fails at line 7 with the following AttributeError: 'str' object has no attribute 'data'
I guess that makes sense because it expects to parse layer 2 Ethernet information that doesn't exist.
I am relatively new to Python and the dpkt documentation has not been much help to me. Does anybody know how I can have dpkt handle these packets that lack the Ethernet information? Or perhaps how to have the router (Cisco 2911, IOS 15.0) export them with Ethernet information in tact?
I feel like there has got to be a simple way to make dpkt handle these dumps, as Wireshark can read them perfectly. Any help is much appreciated! :)