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 ...
随机推荐
- Android View 事件分发机制 源码解析 (上)
一直想写事件分发机制的文章,不管咋样,也得自己研究下事件分发的源码,写出心得~ 首先我们先写个简单的例子来测试View的事件转发的流程~ 1.案例 为了更好的研究View的事件转发,我们自定以一个My ...
- Js前端代码异常监控
window.onerror = function(msg,url,line,col,error){ //没有URL不上报!上报也不知道错误 if (msg != "Script error ...
- LeetCode:LRU Cache
题目大意:设计一个用于LRU cache算法的数据结构. 题目链接.关于LRU的基本知识可参考here 分析:为了保持cache的性能,使查找,插入,删除都有较高的性能,我们使用双向链表(std::l ...
- 在VS中用正则表达式查找或替换
2005VS和2008VS正则替换规则如下(2013VS不适合,不需要的同学可以直接跳到2013VS的操作办法): Example: 查找#incldue中带有gl开头的头文件的,用include.+ ...
- tomcat远程部署应用
Tomcat安装成功后,在ip地址:8080上就可以看见熟悉的首页,在这个首页中,上方有一个manage app按钮,点击就可以进行应用管理了.这样就不需要使用ftp把war包传上去了. 要想远程部署 ...
- string.IsNullOrEmpty和string.IsNullOrWhiteSpace方法的区别
string.IsNullOrEmpty 都知道,这个功能是判断字符串是否为:null或者string.Empty.如果是如"\t"这样的字符就返回false了,为了达到判断过滤这 ...
- Asp.Net MVC<九>:OWIN,关于StartUp.cs
https://msdn.microsoft.com/zh-cn/magazine/dn451439.aspx(Katana 项目入门) 一不小心写了个WEB服务器 快刀斩乱麻之 Katana OWI ...
- python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?
python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdef ...
- MVC复杂模型绑定
当初遇到业务需求ajax提交一组对象数组到服务器.但是苦于mvc的默认绑定器.绑定不上去.好吧只有靠自己了. 当初就是参考这个大大的博客:http://www.cnblogs.com/xfrog/ar ...
- RAM、DRAM、SD卡
catalogue . ROM.RAM.DRAM.SRAM和FLASH的区别 . 内存工作原理 . DRAM基本结构与原理 . SD卡基本结构与原理 1. ROM.RAM.DRAM.SRAM和FLAS ...