获取出cpuid和 maclist。然后进行2次md5运算。完整代码如下
import hashlibdef calculate_device_id():mac_all = "1C1B0D0E9398"cpuidtxt = "3219913727"# 将无符号整数转换为有符号整数cpuid_unsigned = int(cpuidtxt)if cpuid_unsigned > 0x7FFFFFFF: # 如果大于最大有符号整数cpuid_signed = cpuid_unsigned - 0x100000000else:cpuid_signed = cpuid_unsigned# 使用有符号整数参与运算cpuidtxt = str(cpuid_signed)# print(cpuidtxt)# 第一次MD5mac_bytes = bytes.fromhex(mac_all)macmd5 = hashlib.md5(mac_bytes).hexdigest().lower().replace(" ", "")# 组合字符串dev_md5 = macmd5 + cpuidtxt# 第二次MD5dev_bytes = dev_md5.encode('utf-8')dev_hex = dev_bytes.hex()dev_md5 = hashlib.md5(bytes.fromhex(dev_hex)).hexdigest().lower().replace(" ", "")# 添加前缀并截取result = "W" + dev_md5return result[:17]# 使用示例
if __name__ == "__main__":device_id = calculate_device_id()print("生成的设备ID:", device_id)