Get ARP MAC from IP address


/ Published in: Python
Save to your folder(s)

This can be used to get arp mac address from a ip address. Remember that MAC addresses are in arp tables (volatile), that's why a ping is done first. But i don't know if timing between ping call and arp call is enought to make sense (of pinging).


Copy this code and paste it in your HTML
  1. from subprocess import Popen, PIPE
  2. import re
  3. IP = "192.168.10.111"
  4. Popen(["ping", "-c 1", IP], stdout = PIPE)
  5. pid = Popen(["arp", "-n", IP], stdout = PIPE)
  6. s = pid.communicate()[0]
  7. mac = re.search(r"(([a-f\d]{1,2}\:){5}[a-f\d]{1,2})", s).groups()[0]
  8. print "%s--> %s" % (IP, mac)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.