write a python program to read a pcap file using the dpktmodule
Solution
dpkt module is mainly used to construct as well as to parsepackets. Here I’m writing a program to parse the pcap file usingdpkt module.
Steps:
1. Opening the pcap file using reader class.
2. Get into the file, interact with each pcap object in thefile.
3. Passing the packets raw data to the ethernet class to parseand decode.
4. Printing the packet data.
Coding :
import dpkt
# Pass the sample .pcap file toparse.
file = open(‘sample.pcap’)
pcapData = dpkt.pcap.Reader(file)
# Parse through the Pcap file to get the necessarydata
for ss , buff in pcapData:
Ether =dpkt.ethernet.Ethernet(buff)
Ip = Ether.data
Tcp
OR
OR