[英]how can I get MAC-address using IP-address python
how can I get MAC-address using IP-address the following code do not working 如何使用IP地址获取MAC地址,以下代码不起作用
packet = ARP(op=ARP.who_has,psrc="some ip",pdst = ip)
response = srp(packet)
return response[ARP].hwsrc
if you`re using python 3 如果你正在使用python 3
import uuid
def get_mac():
mac_num = hex(uuid.getnode()).replace('0x', '').upper()
mac = '-'.join(mac_num[i: i + 2] for i in range(0, 11, 2))
return mac
print (get_mac())
and if you`re using python 2 如果你正在使用python 2
import uuid
def get_mac():
mac_num = hex(uuid.getnode()).replace('0x', '').upper()
mac = '-'.join(mac_num[i : i + 2] for i in range(0, 11, 2))
return mac
print get_mac()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.