测试

此处使用的是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. BBR拥塞控制算法

    BBR拥塞控制算法是Google最新研发的单边TCP拥塞控制算法Linux 内核4.9 已引入这个BBR算法,本人在CAC测试Ubuntu 14.04 安装Linux 4.9内核,延迟优化效果和TCP ...

  2. 潭州学院-JavaVIP的Javascript的高级进阶-KeKe老师

    潭州学院-JavaVIP的Javascript的高级进阶-KeKe老师 讲的不错,可以学习 下面是教程的目录截图: 下载地址:http://www.fu83.cn/thread-283-1-1.htm ...

  3. ZigZag Conversion leetcode java

    题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows l ...

  4. 跨域的另一种解决方案——CORS(Cross-Origin Resource Sharing)跨域资源共享

    在我们日常的项目开发时使用AJAX,传统的Ajax请求只能获取在同一个域名下面的资源,但是HTML5打破了这个限制,允许Ajax发起跨域的请求.浏览器是可以发起跨域请求的,比如你可以外链一个外域的图片 ...

  5. IIS部署SSL,.crt .key 的证书,怎么部署到IIS,记录一下,以免忘记。

    SSL连接作用不说,百度很多.因为最近想考虑重构一些功能,在登录这块有打算弄成HTTPS的,然后百度了,弄成了,就记录一下,以便以后万一部署的时候忘记掉. 做实验的时候,拿的我个人申请的已经备案的域名 ...

  6. java用selenium库控制chrome

    一.简介 selenium是浏览器自动化工具,可以通过程序来控制浏览器行为,这就是selenium!你可以用它做任何你想做的事情.很多时候人们用它测试web应用,但selenium的用途绝不仅限于此. ...

  7. 51nod DP 最大子段和

    #include<iostream> #include<algorithm> #include<cstdio> #define MAXN 50000 using n ...

  8. jquery里互为逆过程的方法

    jquery里互为逆过程的方法reverse 在jquery里,有不少互为逆过程的方法,如parent()与children(),parents()与find(),first()和last()等,这些 ...

  9. CommonJS,AMD,CMD区别

    学得比较晕,再次看commonjs,amd, cmd时好像还是没完全弄清楚,今天再整理一下: commonjs是用在服务器端的,同步的,如nodejs amd, cmd是用在浏览器端的,异步的,如re ...

  10. Day1-python基础1

    本次学习内容 Python介绍 发展史 版本选择 install 第一个程序hello world 字符编码及注释 变量 用户输入 表达式if...else 一.Python介绍 1)Python由来 ...