Meszias

Scapy arp ping with nmap vendor mac-prefix

Apr 11th, 2013
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # note that this script requires tcpdump to be installed
  3. # additionally, it requires root privs to run.
  4.  
  5. import sys
  6. import logging
  7. logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
  8.  
  9. if len(sys.argv) != 2:
  10.     print "Usage: pingarp \n  eg: pingarp 192.168.1.0/24"
  11.     sys.exit(1)
  12.  
  13. filename = '/usr/share/nmap/nmap-mac-prefixes' # '/usr/local/share/nmap/nmap-mac-prefixes'
  14. vals = {}
  15. with open(filename) as myFile:
  16.     for line in myFile.readlines():        
  17.         vals[line[:6]] = line[7:-1]
  18.  
  19. from scapy.all import srp,Ether,ARP,conf, Dot11Elt
  20. conf.verb=0
  21. ans,unans=srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=sys.argv[1]),
  22.               timeout=2)
  23.  
  24. for snd,rcv in ans:    
  25.     val = rcv.sprintf(r"%Ether.src%").replace(":", "")[:6].upper()    
  26.     print rcv.sprintf(r"%Ether.src%, %ARP.psrc%"), "(%s)" % vals[val] if val in vals else '(Not found)'
Advertisement
Add Comment
Please, Sign In to add comment