从IP地址获取ARP MAC
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从IP地址获取ARP MAC相关的知识,希望对你有一定的参考价值。
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).
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-fd]{1,2}:){5}[a-fd]{1,2})", s).groups()[0] print "%s--> %s" % (IP, mac)
以上是关于从IP地址获取ARP MAC的主要内容,如果未能解决你的问题,请参考以下文章