Python 获取硬盘 主板等生产注册码

cpp 复制代码
import wmi
import random
import os

sec="t95p0q2f6dz1cxmowgjensr7yh384bvualki"
dec="dn7vhlk3wx1efsyc56zu2bomjtq8i0g4rp9a"

c=wmi.WMI()

for physical_disk in c.Win32_DiskDrive():
    hard_seral=physical_disk.SerialNumber #获取硬盘系列号
    print("硬盘系列号为:",hard_seral)
if len(hard_seral)>6:
    hard_seral=hard_seral[-6:]
else:
    print("硬盘信息获取错误!")
    os.exit(0)
for cpu in c.Win32_Processor():
    cpu_seral=cpu.ProcessorId.strip()  #获取CPU系列号
    print("CPU系列号为:",cpu_seral)
if len(cpu_seral)>4:
    cpu_seral=cpu_seral[-4:]
else:
    print("CPU信息获取错误!")
    os.exit(0)
for board_id in c.Win32_BaseBoard():
    board_id=board_id.SerialNumber #获取主板系列号
    print("主板系列号为:",board_id)
if len(board_id)>6:
    board_id=board_id[-5:]
else:
    print("主板信息获取错误!")
    os.exit(0)
seral=hard_seral+cpu_seral+board_id
print("注册码使用的硬件信息为:",seral)
cha_seral=""
for i in range(0,14,2):
    cha_seral+=seral[14-i]+seral[i+1] #字符串尾和首递进连接生成新的字符串
cha_seral=cha_seral+seral[7]          #字符串的中间值放到新的字符串
list_seral=list(cha_seral)            #字符串转为列表
list_seral.reverse()                  #列表反转
rand_seral=""

for i in range(10):             # 将前10个字符串和其位置索引
    j=random.randint(1,len(list_seral))
    rand_seral+=hex(j)[2:]+list_seral[j-1] #hex(j[2:],去掉16进制前的符号0x
    list_seral.remove(list_seral[j-1])
rand_seral=''.join(list_seral)+rand_seral #形成25位的字符串
low_seral=""
rand_seral=rand_seral.lower()
for item in rand_seral:
    j=sec.index(item)
    low_seral+=dec[j]
low_seral=low_seral.upper()
last_seral=low_seral[0:5]+"-"+low_seral[5:10]+"-"+low_seral[10:15]+"-"+low_seral[15:20]+"-"+low_seral[20:25]
print("生成的注册码为:\n",last_seral)
相关推荐
XiaoLeisj11 小时前
Android Kotlin 全链路系统化指南:从基础语法、类型系统与面向对象,到函数式编程、集合操作、协程并发与 Flow 响应式数据流实战
android·开发语言·kotlin·协程
dapeng287012 小时前
分布式系统容错设计
开发语言·c++·算法
2501_9454235412 小时前
用Matplotlib绘制专业图表:从基础到高级
jvm·数据库·python
2301_7938046912 小时前
使用Python处理计算机图形学(PIL/Pillow)
jvm·数据库·python
qq_4176950512 小时前
代码热修复技术
开发语言·c++·算法
badhope17 小时前
Mobile-Skills:移动端技能可视化的创新实践
开发语言·人工智能·git·智能手机·github
码云数智-园园18 小时前
微服务架构下的分布式事务:在一致性与可用性之间寻找平衡
开发语言
吴佳浩18 小时前
GPU 编号进阶:CUDA\_VISIBLE\_DEVICES、多进程与容器化陷阱
人工智能·pytorch·python
C++ 老炮儿的技术栈18 小时前
volatile使用场景
linux·服务器·c语言·开发语言·c++
hz_zhangrl18 小时前
CCF-GESP 等级考试 2026年3月认证C++一级真题解析
开发语言·c++·gesp·gesp2026年3月·gespc++一级