python在windows下获取cpu、硬盘、bios、主板序列号
测试
import os, sys
import time
import wmi,zlib
def get_cpu_info() :
tmpdict = {}
tmpdict["CpuCores"] = 0
c = wmi.WMI()
# print c.Win32_Processor().['ProcessorId']
# print c.Win32_DiskDrive()
for cpu in c.Win32_Processor():
# print cpu
print "cpu id:", cpu.ProcessorId.strip()
tmpdict["CpuType"] = cpu.Name
try:
tmpdict["CpuCores"] = cpu.NumberOfCores
except:
tmpdict["CpuCores"] += 1
tmpdict["CpuClock"] = cpu.MaxClockSpeed
return tmpdict
def _read_cpu_usage():
c = wmi.WMI ()
for cpu in c.Win32_Processor():
return cpu.LoadPercentage
def get_cpu_usage():
cpustr1 =_read_cpu_usage()
if not cpustr1:
return 0
time.sleep(2)
cpustr2 = _read_cpu_usage()
if not cpustr2:
return 0
cpuper = int(cpustr1)+int(cpustr2)/2
return cpuper
def get_disk_info():
tmplist = []
encrypt_str = ""
c = wmi.WMI ()
for cpu in c.Win32_Processor():
#cpu 序列号
encrypt_str = encrypt_str+cpu.ProcessorId.strip()
print "cpu id:", cpu.ProcessorId.strip()
for physical_disk in c.Win32_DiskDrive():
encrypt_str = encrypt_str+physical_disk.SerialNumber.strip()
#硬盘序列号
print 'disk id:', physical_disk.SerialNumber.strip()
tmpdict = {}
tmpdict["Caption"] = physical_disk.Caption
tmpdict["Size"] = long(physical_disk.Size)/1000/1000/1000
tmplist.append(tmpdict)
for board_id in c.Win32_BaseBoard():
#主板序列号
encrypt_str = encrypt_str+board_id.SerialNumber.strip()
print "main board id:",board_id.SerialNumber.strip()
# for mac in c.Win32_NetworkAdapter():
#mac 地址(包括虚拟机的)
# print "mac addr:", mac.MACAddress:
for bios_id in c.Win32_BIOS():
#bios 序列号
encrypt_str = encrypt_str+bios_id.SerialNumber.strip()
print "bios number:", bios_id.SerialNumber.strip()
print "encrypt_str:", encrypt_str
#加密算法
print zlib.adler32(encrypt_str)
return encrypt_str
if __name__ == "__main__":
# a = get_cpu_info()
get_disk_info()
python在windows下获取cpu、硬盘、bios、主板序列号的更多相关文章
- Windows下获取CPU频率
一直想在Windows下取得CPU的时钟速度,找了好久终于找到了函数CallNtPowerInformation,要想使用它,首先必须包含powrprof.h头文件和链接库powerprof.lib. ...
- Windows下获取高精度时间注意事项
Windows下获取高精度时间注意事项 [转贴 AdamWu] 花了很长时间才得到的经验,与大家分享. 1. RDTSC - 粒度: 纳秒级 不推荐优势: 几乎是能够获得最细粒度的计数器抛弃理由: ...
- 如何在Windows下用cpu模式跑通py-faster-rcnn 的demo.py
关键字:Windows.cpu模式.Python.faster-rcnn.demo.py 声明:本篇blog暂时未经二次实践验证,主要以本人第一次配置过程的经验写成.计划在7月底回家去电脑城借台机子试 ...
- Python调用windows下DLL详解
Python调用windows下DLL详解 - ctypes库的使用 2014年09月05日 16:05:44 阅读数:6942 在python中某些时候需要C做效率上的补充,在实际应用中,需要做部分 ...
- c和c++在windows下获取时间和计算时间差的方法总结
c/c++在windows下获取时间和计算时间差的几种方法总结 一.标准C和C++都可用 1.获取时间用time_t time( time_t * timer ),计算时间差使用double diff ...
- Windows下用cpu模式跑通目标检测py-faster-rcnn 的demo.py
关键字:Windows.cpu模式.Python.faster-rcnn.demo.py 声明:原文发表在博客园,未经允许不得转载!!!本篇blog过程已经多名读者实践验证,有人反馈报错TypeErr ...
- windows下获取IP地址的两种方法
windows下获取IP地址的两种方法: 一种可以获取IPv4和IPv6,但是需要WSAStartup: 一种只能取到IPv4,但是不需要WSAStartup: 如下: 方法一:(可以获取IPv4和I ...
- Windows下获取本机IP地址方法介绍
Windows下获取本机IP地址方法介绍 if((hostinfo = gethostbyname(name)) != NULL) { #if 1 ; printf("IP COUNT: % ...
- python 在windows下的 虚拟环境
解决 python 环境问题 windows 下安装 pip install virtualenv virtualenv的基本使用 1.1 创建虚拟环境 virtualenv venv 为环境指定Py ...
随机推荐
- Linux 进程间通讯详解六
ftok()函数 key_t ftok(const char *pathname, int proj_id); --功能:创建系统建立IPC通讯 (消息队列.信号量和共享内存) 时key值 --参数 ...
- <转>打工与乘公交
打工与乘公交 去一个公司打工就如同上了一辆公交车.在上车之前,你应该清楚自己打算去哪里,打算在哪里下车. 有的公交车很豪华,有的很破烂,但是这并不是重点,所有能开到目的地的车都是好车. 上了车之后,也 ...
- 析构函数virtual与非virtual区别 [转]
作为通常的原则,如果一个类定义了虚函数,那么它的析构函数就应当是virtual的.因为定义了虚函数则隐含着:这个类会被继承,并且会通过基类的指针指向子类对象,从而得到多态性. 这个类可能会被继承, ...
- 通过sqlserver发送邮件
配置过程请参考:http://www.2cto.com/database/201403/289114.html 实际中应用的扩展: 1.编写一个触发器(相当于一个多线程的发邮件的服务). 2.在应用程 ...
- JS组件系列——Bootstrap Select2组件使用小结
前言:在介绍select组件的时候,博主之前分享过一篇JS组件系列——两种bootstrap multiselect组件大比拼,这两个组件的功能确实很强大,只可惜没有图文结合的效果(也就是将图片放入到 ...
- 扩展 DbUtility (1)
本文原始路径: https://www.zybuluo.com/Ivony/note/14074 前言 DbUtility v3 是一个开源的轻量级数据库访问框架,源代码通过 Apache 协议发布, ...
- docfx开源啦
废话不多说了,直接上地址: 源代码: https://github.com/dotnet/docfx 文档: http://dotnet.github.io/docfx/ clone git clon ...
- java8日期时间
###与时间有关的5个包* java.time* java.time.chrono* java.time.format* java.time.temporal* java.time.zone###ja ...
- QQ个人文件夹中的文件被占用,解决办法
我的情况是记住密码的账号不可以登录,不记住密码的账号确可以登录,突然就这样,我也很郁闷. 找到路径C:\Users\Public\Documents\Tencent\QQ下的UserDataInfo. ...
- Thinking in java学习笔记之set
Random rand = new Random(47); Set<Integer> set = new HashSet<Integer>(); for(int i=0;i&l ...