测试

此处使用的是wmi库,可以去google里面搜索“python wmi”

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、主板序列号的更多相关文章

  1. Windows下获取CPU频率

    一直想在Windows下取得CPU的时钟速度,找了好久终于找到了函数CallNtPowerInformation,要想使用它,首先必须包含powrprof.h头文件和链接库powerprof.lib. ...

  2. Windows下获取高精度时间注意事项

    Windows下获取高精度时间注意事项 [转贴 AdamWu]   花了很长时间才得到的经验,与大家分享. 1. RDTSC - 粒度: 纳秒级 不推荐优势: 几乎是能够获得最细粒度的计数器抛弃理由: ...

  3. 如何在Windows下用cpu模式跑通py-faster-rcnn 的demo.py

    关键字:Windows.cpu模式.Python.faster-rcnn.demo.py 声明:本篇blog暂时未经二次实践验证,主要以本人第一次配置过程的经验写成.计划在7月底回家去电脑城借台机子试 ...

  4. Python调用windows下DLL详解

    Python调用windows下DLL详解 - ctypes库的使用 2014年09月05日 16:05:44 阅读数:6942 在python中某些时候需要C做效率上的补充,在实际应用中,需要做部分 ...

  5. c和c++在windows下获取时间和计算时间差的方法总结

    c/c++在windows下获取时间和计算时间差的几种方法总结 一.标准C和C++都可用 1.获取时间用time_t time( time_t * timer ),计算时间差使用double diff ...

  6. Windows下用cpu模式跑通目标检测py-faster-rcnn 的demo.py

    关键字:Windows.cpu模式.Python.faster-rcnn.demo.py 声明:原文发表在博客园,未经允许不得转载!!!本篇blog过程已经多名读者实践验证,有人反馈报错TypeErr ...

  7. windows下获取IP地址的两种方法

    windows下获取IP地址的两种方法: 一种可以获取IPv4和IPv6,但是需要WSAStartup: 一种只能取到IPv4,但是不需要WSAStartup: 如下: 方法一:(可以获取IPv4和I ...

  8. Windows下获取本机IP地址方法介绍

    Windows下获取本机IP地址方法介绍 if((hostinfo = gethostbyname(name)) != NULL) { #if 1 ; printf("IP COUNT: % ...

  9. python 在windows下的 虚拟环境

    解决 python 环境问题 windows 下安装 pip install virtualenv virtualenv的基本使用 1.1 创建虚拟环境 virtualenv venv 为环境指定Py ...

随机推荐

  1. Query节点操作,jQuery插入节点,jQuery删除节点,jQuery Dom操作

    一.创建节点 var box = $('<div>节点</div>'); //创建一个节点,或者var box = "<div>节点</div> ...

  2. Android利用Jsoup解析html 开发网站客户端小记。

    这些天业余时间比较多,闲来无事,想起了以前看过开发任意网站客户端的一篇文章,就是利用jsoup解析网站网页,通过标签获取想要的内容.好了废话不多说,用到的工具为 jsoup-1.7.2.jar包,具体 ...

  3. 吉特仓库管理系统-.NET打印问题总结

    在仓储系统的是使用过程中避免不了的是打印单据,仓库系统中包含很多单据:入库单,出库单,盘点单,调拨单,签收单等等,而且还附带着很多的条码标签的打印.本文在此记录一下一个简单的打印问题处理方式.处理问题 ...

  4. 在Windows Server 2012 R2上安装SharePoint 2013 with SP1失败,提示没有.net4.5的解决办法

    现在的Server用Windows Server 2012 R2的越来越多了,在部署带Sp1的SharePoint2013的时候,走完预安装工具后,点击setup提示缺少.net4.5. 其实Wind ...

  5. 【转载】JS中bind方法与函数柯里化

    原生bind方法 不同于jQuery中的bind方法只是简单的绑定事件函数,原生js中bind()方法略复杂,该方法上在ES5中被引入,大概就是IE9+等现代浏览器都支持了(有关ES5各项特性的支持情 ...

  6. python-实现生产者消费者模型

    生产者消费者:包子铺不停的做包子,行人不停的买 ---> 这样就达到了目的--->包子的销售 两个不同的角色 包子铺,行人 只负责单一操作 让包子变成连接的介质. #_*_coding:u ...

  7. VS 团队资源管理 强制解锁锁定文件

    故事是这样发生的: 以前有台电脑,在团队资源里看程序,可能冥冥中不小心按了个空格,so,文件被锁定 而我却没有发现 如果再给我一个机会,我只想说记得签入 然后,高潮来了 重装电脑 欣喜的装好新机子打开 ...

  8. Leetcode 377. Combination Sum IV

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  9. MySQL的insert语句的区别

    SQL Server: insert into tb_articleType (articleType_name,articleType_info) values ("test", ...

  10. a版本冲刺第五天

    队名:Aruba   队员: 黄辉昌 李陈辉 林炳锋 鄢继仁 张秀锋 章  鼎 运动会这几天两位同学准备比赛也确实比较忙,两位同学又刚好有事回家去了,由于之前git解决一次冲突后,远程我们还不能很好地 ...