测试

此处使用的是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. Enum简单例子DropdownList

    借鉴:http://www.cnblogs.com/suizhikuo/archive/2013/06/07/3125225.html vs2012 mvc4 最终效果: 1.建立mvc4 Inter ...

  2. Jquery遮罩插件,想罩哪就罩哪!

    一  前言 在项目开发时发现没有一个用起来 爽一点的遮罩插件,看起来觉得不难 好吧那就利用空闲时间,自己折腾一个吧,也好把jquery再温习一下, 需要的功能如下 1 可以全屏遮 用于提交数据时 2 ...

  3. 如何理解vue.js组件的作用域是独立的

    vue.js组件的作用域是独立,可以从以下三个方面理解: 1.父组件模板在父组件作用域内编译,父组件模板的数据用父组件内data数据:2.子组件模板在子组件作用域内编译,子组件模板的数据用子组件内da ...

  4. c#JS调用

    using MSScriptControl; using System; using System.Collections.Generic; using System.Reflection; usin ...

  5. sharedUserId

    android:sharedUserId sharedUserId的作用是让两个应用程序共享一个user id,我们都知道linux进程给每一个应用程序分配了一个独立的user id,所以如果两个或多 ...

  6. JAVA锁的膨胀过程和优化

    首先说一下锁的优化策略. 1,自旋锁 自选锁其实就是在拿锁时发现已经有线程拿了锁,自己如果去拿会阻塞自己,这个时候会选择进行一次忙循环尝试.也就是不停循环看是否能等到上个线程自己释放锁.这个问题是基于 ...

  7. 软件卸载工具 Uninstall Tool 3.5.1 中文破解版

    Uninstall Tool 是一个小巧.安全.快速.强大的软件卸载删除工具,它支持在使用软件本身的卸载程序卸载完毕后,再扫描软件残留的注册及其它残余文件,将其彻底在系统删除!安装监视器可以监视每个应 ...

  8. mui消息框alert,confirm,prompt,toast

    <script type="text/javascript" charset="utf-8"> //mui初始化 mui.init({ swipeB ...

  9. 【caffe】绘制网络结构图

    @tags caffe 网络结构 可视化 当拿到一份网络定义文件net.prototxt,可以用工具画出网络结构.最快速的方法是使用在线工具netscope,粘贴内容后shift+回车就可以看结果了. ...

  10. BigDecimal 加减乘除

    BigDecimal bignum1 = new BigDecimal("10"); BigDecimal bignum2 = new BigDecimal("5&quo ...