请教一下 Windows 机器码的问题

15 天前
 Motorola3

我用的 这个方式生成的机器码

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 有能保证唯一性的机器码呢

390 次点击
所在节点    问与答
2 条回复
ssgooglg
15 天前
稍微调整一下

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())
Motorola3
15 天前
@ssgooglg 会报一个错 Error: 'utf-8' codec can't decode byte 0xcc in position 23: invalid continuation byte

我让 gpt 给我写了个复杂的 跟你这个差不多

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1049308

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX