Hello everyone, I've just started using the pypcap and dpkt modules and tried the code on google code for pypcap and I get nothing.

Heres the code I used:

import dpkt, pcap
pc = pcap.pcap()
pc.setfilter('icmp')

for ts, pkt in pc:
     print `dpkt.ethernet.Ethernet(pkt)`

I think this is suposed to print all the ICMP packets that are caught on the wire, but I get nothing, even when I ping something.

Theres almost no documentation(that I can find) so I'm unsure what I'm doing wrong. Hopefully someone here can shed some light on this.

Also if someone knows of a tutorial that explains the pypcap module, I would be very happy. I've seen this one and am not getting much from it.

http://jon.oberheide.org/blog/2008/08/25/dpkt-tutorial-1-icmp-echo/

Thanks

EDIT: Also, I'm using python 2.5

Dani AI

Generated

Quick summary and likely causes (based on the thread): on Windows pypcap/pcap will silently show no packets if the capture driver (WinPcap/Npcap) is missing or installed in a mode you cannot access, if you opened the wrong interface, or if the capture is buffered (no immediate mode). The suggestions from and to run with elevated rights are relevant on Windows too — many pcap installs restrict access to administrators. (winpcap.org)

Practical checklist (do these in order):

  • Confirm a packet driver is installed (prefer Npcap on modern Windows). Npcap supports loopback and has a WinPcap-compatible install mode. (npcap.com)
  • List available interfaces with pypcap so you’re sure you’re opening the interface that sees your ping traffic (pcap exposes a findalldevs call). Then open that device explicitly and enable immediate mode and a small timeout so packets arrive to the app without long buffering. (github.com)

Example (minimal verification — list interfaces, then open one):

import pcap

# list adapters
for dev in pcap.findalldevs():
    print(dev)

# open the adapter you saw above (use the exact device string)
pc = pcap.pcap(name='\\Device\\NPF_{...}', promisc=True, immediate=True, timeout_ms=50)
pc.setfilter('icmp')
for ts, buf in pc:
    print(ts, len(buf))

If you get packets but your current print shows nothing useful, decode with dpkt to check packet types (Ethernet → IP → ICMP) and print ICMP type/code rather than just the object repr — dpkt docs include a short ICMP example that shows this nesting. (dpkt.readthedocs.io)

Extra troubleshooting tips: run the Python process explicitly "Run as Administrator" (UAC/elevation matters); if findalldevs() returns nothing or only loopback, reinstall Npcap with WinPcap-API and loopback options; ensure the pypcap binary matches your Python architecture (32 vs 64 bit). References: pypcap README and Npcap docs explain the interface and Windows notes. (github.com)

Recommended Answers

All 4 Replies

Make sure you are the root! In C program I have had the same problem when I run the program as common user, but I got the right result when I sudo it.

I'm on windows, so I don't think thats the problem.

Thanks though.

I'm on windows, so I don't think thats the problem.

Hah, I think that might be your exact problem, especially if you're on Vista. Try a good old 'Run as Administrator.' And maybe implement something like so:

import os

if os.geteuid() != 0:
  print "You must be root to run this script."

Sorry for the late reply, I checked and I am administrator.

I tried your code just to make sure, but I get an error. Its nothing with your code just my installation, I think.

One thing though, is the administrator account that you get to by going into safe mode have the same privileges as an account that you create as an administrator.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.