Python获取本机所有网卡的MAC地址
1、获取单个网卡MAC地址
>>> import uuid
>>> address = hex(uuid.getnode())[2:]
>>> '-'.join(address[i:i+2] for i in range(0, len(address), 2))
'f0-03-8c-09-8c-34'
2、获取多网卡MAC地址
首先使用pip安装Python扩展库psutil,然后执行下面的代码即可。
from psutil import net_if_addrs
for k, v in net_if_addrs().items():
for item in v:
address = item[1]
if '-' in address and len(address)==17:
print(address)