Return to Snippet

Revision: 63232
at April 18, 2013 00:18 by someguy123

Initial Code
from subprocess import Popen, PIPE
import re
IP = ""
Popen(["ping", "-c 1", IP], stdout = PIPE)
pid = Popen(["arp", "-n", IP], stdout = PIPE)
s = pid.communicate()[0]
mac ="(([a-f\d]{1,2}\:){5}[a-f\d]{1,2})", s).groups()[0]
print "%s--> %s" % (IP, mac)

Initial URL

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

Initial Title
Get ARP MAC from IP address

Initial Tags
mac, ip

Initial Language