测试

此处使用的是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. ConcurrentHashMap和HashMap的一点区别

    HashMap不是线程安全的,ConcurrentHashMap则在某一个方法的执行上是线程安全的. package testMap; import java.util.HashMap; public ...

  2. SQL Server日志文件(LDF文件)

    一.日志文件过大处理方法: 1.设置数据库模式为简单模式:ALTER DATABASE 数据库名 SET RECOVERY SIMPLE 或者选中数据库-属性-选项-恢复模式设置为简单. 2.收缩日志 ...

  3. 屏蔽防止被别的网站嵌入框架代码(防止被人frame)

    <SCRIPT LANGUAGE=javascript> if (top.location != self.location)top.location=self.location; < ...

  4. php 异常处理类

    PHP具有很多异常处理类,其中Exception是所有异常处理的基类. Exception具有几个基本属性与方法,其中包括了: message 异常消息内容code 异常代码file 抛出异常的文件名 ...

  5. 使用Cordova和JQM在ios上需要注意的问题

    1.ios编译 cordova platform add ios --save cordova build ios 2.IOS 微信和地图調用問題:因IOS 9.0以上版本白名單限制,衹有加入白名單的 ...

  6. Mongodb学习笔记二(Mongodb基本命令)

    第二章 基本命令 一.Mongodb命令 说明:Mongodb命令是区分大小写的,使用的命名规则是驼峰命名法. 对于database和collection无需主动创建,在插入数据时,如果databas ...

  7. IoC模式(依赖、依赖倒置、依赖注入、控制反转)

    1.依赖 依赖就是有联系,有地方使用到它就是有依赖它,一个系统不可能完全避免依赖.如果你的一个类或者模块在项目中没有用到它,恭喜你,可以从项目中剔除它或者排除它了,因为没有一个地方会依赖它.下面看一个 ...

  8. 【BZOJ 1087】【SCOI 2005】互不侵犯King

    http://www.lydsy.com/JudgeOnline/problem.php?id=1087 很简单的状压,需要预处理,我两个状态可不可以挨着的预处理出错WA了好几次. 这个位运算预处理好 ...

  9. cogs 577 蝗灾 CDQ分治

    第一道CDQ,抄了下helenkeller的代码,感觉和归并排序差不多... 因为左半边的修改肯定在右半边的询问之前,所以就不用管时间的限制了,可以直接x轴排序树状数组处理y轴... #include ...

  10. hihoCoder 后缀数组 重复旋律

    #1403 : 后缀数组一·重复旋律 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一个音乐旋律被表示为长度为 N 的数构成 ...