How to process packet captures with Python's dpkt module

502 Views Asked by At

I am trying to write a python program to parse packet capture using dpkt module. I have used it on packet captures that had Ethernet and tcpdump captures and it worked fine. However, my current packet capture is raw packet capture that directly has IP header and subsequent protocols and it seems like dpkt is not able to understand these captures. Picture of capture file is attached. enter image description here

The code I had was

f = open(ipfile, 'rb')

pcap = dpkt.pcap.Reader(f)

for ts,buf in pcap:
    eth = dpkt.ethernet.Ethernet(buf) //Also tried with eth = dpkt.sll.SLL(buf), but no luck.
    ip = eth.data
    tcp = ip.data

Any ideas on how to parse such captures?

Thanks !!

1

There are 1 best solutions below

0
Abdu On

I had the same issue with CAIDA pcap. Try

ip = dpkt.ethernet.Ethernet(buf)