修复 python 中 scapy.all 模块中的错误

fix an error in scapy.all module in python

当用 scapy 编写网络扫描器时:

import scapy.all as scapy

arp = scapy.ARP(pdst='192.168.1.1/24')
broadcast = scapy.Ether(dst='ff:ff:ff:ff:ff:ff')

final_packet = broadcast/arp

answered , unanswered = scapy.srp(final_packet,timeout=1)
print(answered.summary())

然后我得到以下错误:

Traceback (most recent call last):
  File "network_scanner.py", line 8, in <module>
    answered , unanswered = scapy.srp(final_packet,timeout=1)
  File "/home/mohammad/.local/lib/python3.6/site-packages/scapy/sendrecv.py", line 504, in srp
    filter=filter, nofilter=nofilter, type=type)
  File "/home/mohammad/.local/lib/python3.6/site-packages/scapy/arch/linux.py", line 467, in __init__
    self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))  # noqa: E501
  File "/usr/lib/python3.6/socket.py", line 144, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted

如何解决???

你应该运行你的脚本作为 root。

Root privileges are needed to send the packets

来源:Usage - Starting Scapy