python---硬件序列号

安装wmi :

pip install wmi -i https://pypi.douban.com/simple

还要安装  pip install pywin32 

import wmi



c = wmi.WMI()
zuban=c.Win32_BaseBoard()[0].SerialNumber.strip()   #获取主板序列号
#BSN12345678901234567

cpu=c.Win32_Processor()[0].ProcessorId.strip()  #获取cpu序列号
#BFEBFBFF000306A9

yinpan=c.Win32_DiskDrive()[0].SerialNumber.strip()  #硬盘序列号
#S2Y4J9ADA29166

neicun=c.Win32_PhysicalMemory()[0].SerialNumber.strip()  #内存序列号
#E3806262

#网卡mac地址:
def macAddress():#获取网卡mac信息函数
    macs = []
    for n in  c.Win32_NetworkAdapter():
        mactmp = n.MACAddress
        if mactmp and len(mactmp.strip()) > 5:
            tmpmsg = {}
            tmpmsg['MACAddress'] = n.MACAddress
            tmpmsg['Name'] = n.Name
            tmpmsg['DeviceID'] = n.DeviceID
            tmpmsg['AdapterType'] = n.AdapterType
            tmpmsg['Speed'] = n.Speed
            macs.append(tmpmsg)
    return macs[0]['MACAddress']  #返回第一个网卡的mac地址【24:FD:52:3C:ED:8F】。macs包含所有网卡信息

m=macAddress()

print(cpu)
print(zuban)
print(yinpan)
print(neicun)
print(m)

获取mac地址

import uuid
x = uuid.getnode()  #获取十进制的mac地址
#<class 'int'> 128437435448900

原文地址:https://www.cnblogs.com/liming19680104/p/11858635.html