蟒蛇鲷"NameError: global name 'LOOPBACK_NAME' is not defined"



我有一个非常简单的scapy程序,它对我的子网进行arp_ping

from scapy.all import srp, Ether, ARP, conf
def arp_ping(subnet):
    conf.verb = 1
    answered, unanswered = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=subnet),timeout=2,verbose=False, inter=0.1)
    return [rcv.sprintf(r"%Ether.src% - %ARP.psrc%") for snd, rcv in answered]
if __name__=="__main__":
    subnet = '192.168.1.0/24'
    for i in arp_ping(subnet):
        print i

编辑

重新安装至少 PyWin32 并使用 choco WinPcap后,我现在有一个这个名称错误

Traceback (most recent call last):
  File "arp_sender.py", line 1, in <module>
    from scapy.all import srp, Ether, ARP, conf
  File "C:Python27libsite-packagesscapyall.py", line 16, in <module>
    from scapy.arch import *
  File "C:Python27libsite-packagesscapyarch__init__.py", line 83, in <module>
    from scapy.arch.windows import *
  File "C:Python27libsite-packagesscapyarchwindows__init__.py", line 465, in <module>
    conf.iface = get_working_if()
  File "C:Python27libsite-packagesscapyarchwindows__init__.py", line 463, in get_working_if
    return LOOPBACK_NAME
NameError: global name 'LOOPBACK_NAME' is not defined

检查缺陷问题

运行scapy.bat以检查缺陷会导致以下消息:

INFO: Can't load Python libreadline or completer
INFO: Can't import matplotlib. Won't be able to plot.
INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
WARNING: No match between your pcap and windows network interfaces found. You probably won't be able to send packets. Deactivating unneeded interfaces and restarting Scapy might help.Check your winpcap and powershell installation, and access rights.
INFO: Could not get readline console. Will not interpret ANSI color codes.
WARNING: No default IPv4 routes found. Your Windows release may no be supported and you have to enter your routes manually
Traceback (most recent call last):
  File "C:Python27Scripts\scapy", line 25, in <module>
    interact()
  File "C:Python27libsite-packagesscapymain.py", line 300, in interact
    scapy_builtins = __import__("all",globals(),locals(),".").__dict__
  File "C:Python27libsite-packagesscapyall.py", line 16, in <module>
    from scapy.arch import *
  File "C:Python27libsite-packagesscapyarch__init__.py", line 83, in <module>
    from scapy.arch.windows import *
  File "C:Python27libsite-packagesscapyarchwindows__init__.py", line 465, in <module>
    conf.iface = get_working_if()
  File "C:Python27libsite-packagesscapyarchwindows__init__.py", line 463, in get_working_if
    return LOOPBACK_NAME
NameError: global name 'LOOPBACK_NAME' is not defined

我的猜测是:

WARNING: No match between your pcap and windows network interfaces found. You probably won't be able to send packets. Deactivating unneeded interfaces and restarting Scapy might help.Check your winpcap and powershell installation, and access rights.

导致问题,但我不确定如何解决这个问题。

您使用的是旧的 scapy 版本,请通过以下方式更新它 获得 2.4.0 pip install scapy --upgrade

我可以看到,因为最新版本不再需要自由线

在最新版本中,唯一需要安装的依赖项是:

  • Winpcap 或 Npcap
  • IPython(如果被问到)

您可能以非管理员身份运行了 Python 代码。

当我使用PyCharm IDE时,我刚刚遇到了同样的问题,它没有在管理员模式下打开(默认情况下)。以管理员身份重新启动 IDE 后,错误消息消失了。

同样,当你想在Linux中使用scapy库时,你必须指定"sudo ..."

相关内容

最新更新