python获取电脑有线/无线网卡MAC地址信息
程序员文章站
2024-02-19 15:35:52
...
一、获取有线网络的MAC地址
def get_pc_mac_address(self):
"""
获取电脑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
二、获取无线网络MAC地址
def get_MACAddress(self):
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
三、获取PC的Mac地址,返回大写地址
def get_pc_mac_address_upper(self):
"""
获取PC的Mac地址,返回大写地址,如:F8-A2-D6-CC-BB-AA
:return:
"""
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
上一篇: IE userData
下一篇: Mac OS安装配置多个版本的JDK