• python在windows下获取cpu、硬盘、bios、主板序列号


    测试

    此处使用的是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()

  • 相关阅读:
    使用 mesh 实现多边形裁剪图片!Cocos Creator!
    如何实现高抛平抛发射?从抛物线说起!Cocos Creator!
    用 shader effect 实现雨滴落水效果!Cocos Creator 3D !
    反复横跳的瞄准线!从向量计算说起!基于射线检测的实现!Cocos Creator!
    爬取网易云音乐评论!python 爬虫入门实战(六)selenium 入门!
    浅析射线检测 raycast 的使用 !Cocos Creator 3D !
    用 python 分析基金!让赚钱赢在起跑线!
    cocos creator 3D | 拇指投篮 | 3D项目入门实战
    GA/T 1545-2019 信息安全技术 智能密码钥匙安全技术要求
    GA/T 1539-2018 信息安全技术 网络病毒监控系统安全技术要求和测试评价方法
  • 原文地址:https://www.cnblogs.com/testlife007/p/5702568.html
Copyright © 2020-2023  润新知