我有一个非常简单的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
编辑
用choco重新安装atleast
PyWin32
和WinPcap
后,现在出现此NameError:Traceback (most recent call last):
File "arp_sender.py", line 1, in <module>
from scapy.all import srp, Ether, ARP, conf
File "C:\Python27\lib\site-packages\scapy\all.py", line 16, in <module>
from scapy.arch import *
File "C:\Python27\lib\site-packages\scapy\arch\__init__.py", line 83, in <module>
from scapy.arch.windows import *
File "C:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 465, in <module>
conf.iface = get_working_if()
File "C:\Python27\lib\site-packages\scapy\arch\windows\__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:\Python27\Scripts\\scapy", line 25, in <module>
interact()
File "C:\Python27\lib\site-packages\scapy\main.py", line 300, in interact
scapy_builtins = __import__("all",globals(),locals(),".").__dict__
File "C:\Python27\lib\site-packages\scapy\all.py", line 16, in <module>
from scapy.arch import *
File "C:\Python27\lib\site-packages\scapy\arch\__init__.py", line 83, in <module>
from scapy.arch.windows import *
File "C:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 465, in <module>
conf.iface = get_working_if()
File "C:\Python27\lib\site-packages\scapy\arch\windows\__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.
是造成此问题的原因,但是我不确定如何解决此问题。
最佳答案
您使用的是旧版本,请通过以下方式进行更新pip install scapy --upgrade
获得2.4.0
我可以看到,因为最新版本不再需要libreadline
在最新版本中,您需要安装的唯一依赖项是:
Winpcap或Npcap
IPython(如果询问)
关于python - Python Scapy“NameError:未定义全局名称'LOOPBACK_NAME'”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46683337/