获取MAC地址和硬盘序列号

1.获取MAC地址

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)

2.获取硬盘序列号

import wmi

c=wmi.WMI()

def printDisk():
    disks = []
    for disk in c.Win32_DiskDrive():
        # print disk.__dict__
        tmpmsg = {}
        tmpmsg['SerialNumber'] = disk.SerialNumber.strip()
        tmpmsg['DeviceID'] = disk.DeviceID
        tmpmsg['Caption'] = disk.Caption
        tmpmsg['Size'] = disk.Size
        tmpmsg['UUID'] = disk.qualifiers['UUID'][1:-1]
        disks.append(tmpmsg)
    for d in disks:
        print (d)
    return disks
printDisk()

你可能感兴趣的:(获取MAC地址和硬盘序列号)