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 ...
随机推荐
- Python 字符串
Python访问字符串中的值 Python不支持单字符类型,单字符也在Python也是作为一个字符串使用. Python访问子字符串,可以使用方括号来截取字符串,如下实例: #!/usr/bin/py ...
- C#基础系列——反射笔记
前言:使用反射也有几年了,但是一直觉得,反这个概念很抽象,今天有时间就来总结下这个知识点. 1.为什么需要反射: 最初使用反射的时候,作为小菜总是不理解,既然可以通过new 一个对象的方式得到对象,然 ...
- OpenGL在Ubuntu 14.04 中的设置与编程
在sudo apt-get install XXX,别的教程讲的很详细了. 编写好程序需要在shell中链接 g++ teapot.c -o teapot -lglut -lGL -lGLU 此处要注 ...
- 【跟着子迟品 underscore】Array Functions 相关源码拾遗 & 小结
Why underscore 最近开始看 underscore.js 源码,并将 underscore.js 源码解读 放在了我的 2016 计划中. 阅读一些著名框架类库的源码,就好像和一个个大师对 ...
- Loogn.OrmLite映射优化记录
大家对ORM效率的争议多半在映射性能方面.自己的ORMLite也是如此,经过前段时间的折腾,已经找不出一个简单的方法再提升一下这部分的方法了.在此把优化涉及的几点记录一下. 注:用于性能测试的Code ...
- VUE --- 给页面加点网络动态数据
这时候的页面都是静态的(数据在写程序的时候已经固定了不能修改),而每个应用基本上都会请求外部数据以动态改变页面内容.对应有一个库叫 vue-resource 帮我们解决这个问题. 使用命令行安装 cn ...
- elk的搭建----待续
http://yanliu.org/2015/08/19/ELK-redis%E6%90%AD%E5%BB%BAnginx%E6%97%A5%E5%BF%97%E5%88%86%E6%9E%90%E5 ...
- APiCloud真机调试需要注意的几个问题
具体请看官方文档:http://docs.apicloud.com/Dev-Tools/wifi-debug. APiCloud Android手机真机调试,需要首先在手机上安装官网提供的apploa ...
- TYVJ1338 QQ农场
时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 Sandytea前段时间沉迷于QQ农场中……一天夜里,他梦见来到好友X的农场上…… 描述 这个农场和游戏中略有 ...
- 解析Java类和对象的初始化过程
类的初始化和对象初始化是 JVM 管理的类型生命周期中非常重要的两个环节,Google 了一遍网络,有关类装载机制的文章倒是不少,然而类初始化和对象初始化的文章并不多,特别是从字节码和 JVM 层次来 ...