V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Motorola3
V2EX  ›  问与答

请教一下 Windows 机器码的问题

  •  
  •   Motorola3 · 11 天前 · 357 次点击

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

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

    2 条回复    2024-06-13 18:25:22 +08:00
    ssgooglg
        1
    ssgooglg  
       11 天前
    稍微调整一下

    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
        2
    Motorola3  
    OP
       11 天前   ❤️ 1
    @ssgooglg 会报一个错 Error: 'utf-8' codec can't decode byte 0xcc in position 23: invalid continuation byte

    我让 gpt 给我写了个复杂的 跟你这个差不多
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2986 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 13:09 · PVG 21:09 · LAX 06:09 · JFK 09:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.