Python Forum

Full Version: Reading PCAP FIles
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi peeps!!
i need someone expertise to help me

I am trying to read a pcap file with a program im making but im having problems
If anyone has an idea how can i start, i already have the file i need the program to read, im just having problems trying to read it
(Apr-26-2019, 03:41 AM)Variables Wrote: [ -> ]I am trying to read a pcap file with a program im making but im having problems
post your code in python tags, full traceback you get in error tags and ask specific questions. We are glad to help, but we don't write code for you
Okay Guys!

Im new here so im a bit lost, i dont know much about python, im learning
Im doing this program which im trying to make it read a PCAP file(test1.pcap).

When i try to print the output, nothing appears. Can someone help

Thanks
import dpkt

f = open('test1.pcap')
pcap = dpkt.pcap.Reader(f)
f.close()
well, there is no print in your code...

did you read the tutorial from the docs: https://jon.oberheide.org/blog/2008/10/1...pcap-file/
it looks pretty outdated, but should help you start and improve from there
When i insert print, <dpkt.pcap.Reader object at 0x0000000003870EF0> this happens
The idea of this program is to see how many packets i have, I just want to print the whole file
it's a Reader object
you can iterate over it and print each packet as shown in the tutorial
or you can use Reader.readpkts() method to get a list and print it. If you just want the number of packets I guess you can print just the len
Not tested but
import dpkt
 
with open('test1.pcap', 'rb') as f:
    pcap = dpkt.pcap.Reader(f)
    packets = pcap.readpkts()

print(len(packets))
print(packets)
note that you will need to process packets further in order to extract info - see how they use Ethernet class in the tutorial