Posted By

someguy123 on 04/18/13


Tagged

mac ip address arp


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

thastyle


Get ARP MAC from IP address


 / Published in: Python
 

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).

  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  

You need to login to post a comment.