簡體   English   中英

如何使用IP-address python獲取MAC地址

[英]how can I get MAC-address using IP-address python

如何使用IP地址獲取MAC地址,以下代碼不起作用

packet = ARP(op=ARP.who_has,psrc="some ip",pdst = ip)
response = srp(packet)
return response[ARP].hwsrc

如果你正在使用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())

如果你正在使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM