Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple arp scanner written in python (Scapy module)
#! /usr/bin/python
#Author == @avicoder
import sys,getopt
r = '\033[31m' #red
b = '\033[34m' #blue
g = '\033[32m' #green
y = '\033[33m' #yellow
m = '\033[34m' #magenta
c = '\033[36m' #cyan
def main(argv):
if len(sys.argv) < 5:
print m+"\nInvalid Arguments"
print b+ 'arp.py -i <interface> -r <ip range>'
sys.exit()
interface=''
ip_range=''
try:
opts, args = getopt.getopt(argv,"hi:r:",["iface=","ips="])
except KeyInterrupt:
print 'arp.py -i <interface> -r <ip range>'
sys.exit(1)
for opt,arg in opts:
if opt=='-h':
print b+ 'arp.py -i <interface> -r <ip range>'
sys.exit()
elif opt in ("-i","--iface"):
interface=arg
elif opt in ("-r","--ips"):
ip_range=arg
print y+"\nScanning ..."
from scapy.all import srp,Ether,ARP,conf
conf.verb=0
ans,uans=srp(Ether(dst="FF:FF:FF:FF:FF:FF")/ARP(pdst=ip_range),timeout=2,iface=interface,inter=0.1)
for snd,rcv in ans:
print c+rcv.sprintf(r"%Ether.src% - %ARP.psrc%")
print m+"\nScan complete"
if __name__ == "__main__":
main(sys.argv[1:])
@Shivam60

This comment has been minimized.

Copy link

@Shivam60 Shivam60 commented Sep 17, 2017

Can you give a sample test case. As to how this program works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment