简体   繁体   中英

How would I make a packet sniffer in python?

I used a code snippet from stackoverflow, I can't find the post now, but this is what it was

from scapy.all import *
sniff(filter="192.168.1.25", prn=lambda x:x.sprintf("{IP:%IP.src% -> %IP.dst%\n}")

I'm getting an unexpected EOF while parsing

I don't know much about scapy, nor socket. I have no idea how to approach it. Can anyone provide a working example below? I've looked all over and was unable to find one, and this topic has been dead for years

I'm not really willing to learn socket/scapy, just want an example, something temporary, so if socket is the best, post below

this was a known Issue a year ago, try upgrading pip ,then reinstall scapy using

pip install scapy --upgrade if this doesn't cut it.

Download the developer version https://github.com/secdev/scapy/archive/master.zip you might run into different errors but this fixes you current error.

Try this:

from scapy.sendrecv import sniff

sniff(filter="192.168.1.25", prn=lambda x: x.sprintf("{IP:%IP.src% -> %IP.dst%\n}"))

The above post was correct, this was fixed ages ago. please update against the RC versions:

pip install scapy --pre --upgrade

Note: the --pre enables RC versions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM