Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading PCAP FIles
#1
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
Reply
#2
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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()
Reply
#4
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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
Reply
#6
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading Multiple text Files in pyhton Fatim 1 1,885 Jun-25-2021, 01:37 PM
Last Post: deanhystad
  Trouble reading files using pyexcel codebeacon 2 2,136 Feb-08-2021, 05:53 AM
Last Post: codebeacon
  Reading txt files in ssh server. therenaydin 6 4,021 Aug-06-2020, 05:17 AM
Last Post: ndc85430
  How to stop the reading of files Laplace12 4 2,312 Jul-27-2020, 04:07 PM
Last Post: Gribouillis
  how to count a retransmission packets from pcap file? salwa17 0 2,786 Jul-04-2020, 11:22 PM
Last Post: salwa17
  How to extract MSS (maximum size segment) from a pcap file ? salwa17 0 1,643 Jun-29-2020, 09:06 AM
Last Post: salwa17
  Counter of the duplicated packets from a pcap file salwa17 8 4,141 Jun-26-2020, 11:31 PM
Last Post: salwa17
  How can I speed up my openpyxl program reading Excel .xlsx files? deac33 0 3,360 May-04-2020, 08:02 PM
Last Post: deac33
  Other modules for reading audio files? jedzz 0 1,568 Mar-25-2020, 11:07 PM
Last Post: jedzz
  Error With Reading Files In Directory And Calculating Values chascp 2 2,379 Feb-15-2020, 01:57 PM
Last Post: chascp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020