简体   繁体   中英

I'm getting error during sniff packet using scapy

My code is here:

#!/usr/bin/env python3
import os
print(os.sys.path)
from scapy.all import*
def sniff(interface):
    scapy.sniff(iface=interface, store=False, prn=process_sniffed_packet)

def process_sniffed_packet(packet):
    print(packet)

sniff("eth0")

And got the error code like this:

python3 row.py

['/home/kali/Desktop', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.7/dist-packages']
Traceback (most recent call last):
  File "row.py", line 11, in <module>
    sniff("eth0")
  File "row.py", line 6, in sniff
    scapy.sniff(iface=interface, store=False, prn=process_sniffed_packet)
AttributeError: module 'scapy' has no attribute 'sniff'

Could anyone help?

You just imported all available functions from scapy with from scapy.all import * which means you have to use sniff instead of scapy.sniff

If you want to use scapy.sniff you have to change your import to import scapy.all as scapy

Note: There is a sniff function in scapy.all but you are defining a new sniff function (line 5). Rename it so that you don't get name conflicts.

#!/usr/bin/env python3
import os
print(os.sys.path)
from scapy.all import *
def mysniff(interface):
    sniff(iface=interface, store=False, prn=process_sniffed_packet)

def process_sniffed_packet(packet):
    print(packet)

mysniff("eth0") 

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