Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading PCAP FIles
#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


Messages In This Thread
Help reading pcap files - by Variables - Apr-26-2019, 03:41 AM
RE: Reading PCAP FIles - by buran - Apr-26-2019, 05:43 AM
RE: Reading PCAP FIles - by Variables - Apr-26-2019, 05:44 AM
RE: Reading PCAP FIles - by buran - Apr-26-2019, 06:05 AM
RE: Help reading pcap files - by buran - Apr-26-2019, 05:00 AM
Reading PCAP FIles - by Variables - Apr-26-2019, 05:30 AM

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