/ 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).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
from subprocess import Popen, PIPE import re IP = "192.168.10.111" Popen(["ping", "-c 1", IP], stdout = PIPE) pid = Popen(["arp", "-n", IP], stdout = PIPE) s = pid.communicate()[0] mac = re.search(r"(([a-f\d]{1,2}\:){5}[a-f\d]{1,2})", s).groups()[0] print "%s--> %s" % (IP, mac)