从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).
  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-fd]{1,2}:){5}[a-fd]{1,2})", s).groups()[0]
  8. print "%s--> %s" % (IP, mac)

以上是关于从IP地址获取ARP MAC的主要内容,如果未能解决你的问题,请参考以下文章

IP地址利用ARP协议获取MAC地址进行数据包的传送

IP地址利用ARP协议获取MAC地址进行数据包的传送

ARP 协议

ARP协议

Python通过snmp获取交换机VLAN号VLAN默认网关VLAN子网掩码和ARP表中的IP地址与MAC对应记录数据

路由老是发送ARP,查找自己MAC地址的IP,得到自己确定,又继续发送?这是怎么回事啊?