Scapy 不接受这种值“10.0.2.1/24”
The Scapy is not accepting this kind of value "10.0.2.1/24"
我的代码应该发送数据包并取回 mac 地址,但我遇到了一些错误,
代码:
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
print(arp_request_broadcast.summary())
scan("10.0.2.1/24")
错误是:
Ether / ARP who has ?? says ??
你传给ARP层的值就好了。
但是你的代码没有sending/receiving任何数据包到网络。
让我们修复您的代码:
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 中的代码,因为它需要 read/write 到网络
你可以在这里看到完整的解决方案:https://www.thepythoncode.com/article/building-network-scanner-using-scapy
我的代码应该发送数据包并取回 mac 地址,但我遇到了一些错误, 代码:
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
print(arp_request_broadcast.summary())
scan("10.0.2.1/24")
错误是:
Ether / ARP who has ?? says ??
你传给ARP层的值就好了。 但是你的代码没有sending/receiving任何数据包到网络。
让我们修复您的代码:
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 中的代码,因为它需要 read/write 到网络
你可以在这里看到完整的解决方案:https://www.thepythoncode.com/article/building-network-scanner-using-scapy