wmi模块
import wmi
w = wmi.WMI()
for n in w.Win32_NetworkAdapter():
if n.MACADDress is None or n.PhysicalAdapter is False:
continue
mac = n.MACADDress
name = n.Name
if "PCI" in name:
# 有线网卡
print("%s: %s" % (name, mac))
wmi获取当前在使用的网卡
def get_pc_mac_address():
"""
获取电脑mac地址
:return: 电脑mac地址,如:f8a2d60123456
"""
print('\n========= 获取电脑mac地址 =========')
global s
import wmi
s = wmi.WMI()
network = []
for nw in s.Win32_NetworkAdapterConfiguration(IPEnabled=1):
network.append(
{
"MAC": nw.MACAddress,
"ip": nw.IPAddress
}
)
MACAddress = str(nw.MACAddress).replace(':', '')
print("MACAddress={}".format(MACAddress))
return MACAddress
uuid获取的pcmac
def get_pc_mac_address_upper():
"""
获取PC的Mac地址,返回大写地址,如:F8-A2-D6-CC-BB-AA
:return:
"""
import uuid
print('\n========= 获取电脑mac地址 =========')
mac = uuid.UUID(int=uuid.getnode()).hex[-12:]
# 转大写
mac_1 = "-".join([mac[e:e + 2] for e in range(0, 11, 2)]).upper()
print('pc_mac_1={}'.format(mac_1))
return mac_1
标签:MACAddress,wmi,地址,获取,mac,模块,print
From: https://www.cnblogs.com/sunxiuwen/p/17312883.html