python 获取电脑MAC地址
1.获取PC的Mac地址,返回大写地址,如:F8-A2-D6-CC-BB-AA
import uuiddef get_pc_mac_address_upper(): """ 获取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
2.获取电脑mac地址,如:f8a2d60123456
def get_pc_mac_address(): """ 获取电脑mac地址 :return: 电脑mac地址,如:f8a2d60123456 """ print('\n========= 获取电脑mac地址 =========') global s 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