我用的 这个方式生成的机器码
def get_machine_code():
# 获取机器码
try:
# 使用 wmic 命令获取硬件信息
result = (
subprocess.check_output("wmic csproduct get uuid", shell=True)
.decode()
.split("\n")[1]
.strip()
)
return result
except Exception as e:
print(f"Error: {e}")
return None
我发现有好几个人生成出来的都是 0300200-0400-0500-0006-000700080009 这种纯数字是为什么呀 Windows 有能保证唯一性的机器码呢
![]() |
1
ssgooglg 13 天前
稍微调整一下
import subprocess import hashlib def get_hardware_info(command): try: result = subprocess.check_output(command, shell=True).decode().strip().split("\n")[1].strip() return result except Exception as e: print(f"Error: {e}") return None def get_machine_code(): # 获取硬件信息 uuid = get_hardware_info("wmic csproduct get uuid") serial_number = get_hardware_info("wmic bios get serialnumber") mac_address = get_hardware_info("getmac /fo csv /nh") # 组合信息 info = f"{uuid}-{serial_number}-{mac_address}" # 生成哈希值以保证唯一性和标准长度 machine_code = hashlib.sha256(info.encode()).hexdigest() return machine_code if __name__ == '__main__': print(get_machine_code()) |