您传递给层 ARP 的值就可以了。但是您的代码没有向网络发送/接收任何数据包。
让我们修复您的代码:
from scapy.all import ARP, Ether, srp
import scapy.all as scapy
def scan(ip):
arp_request = scapy.ARP(pdst=ip)
broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_request_broadcast = broadcast/arp_request
# send packet to the network, wait for replies for 3 secondes, then return all the answers
result = srp(arp_request_broadcast, timeout=3, verbose=0)[0]
# for each replay,
for sent, received in result:
print(received.summary())
scan("192.168.1.1/24")
在我的网络中给了我:
Ether / ARP is at 00:24:46:03:87:11 says 192.168.1.195 / Padding
Ether / ARP is at f8:75:a4:76:68:36 says 192.168.1.216 / Padding
Ether / ARP is at 78:96:84:9c:13:20 says 192.168.1.254 / Padding
请注意,您需要在 sudo 中运行该代码,因为它需要读取/写入网络
你可以在这里看到完整的解决方案:https ://www.thepythoncode.com/article/building-network-scanner-using-scapy