博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python - wmi模块学习(windwos硬件信息获取)
阅读量:5304 次
发布时间:2019-06-14

本文共 2769 字,大约阅读时间需要 9 分钟。

获取windows操作系统的硬件信息

#!/usr/bin/env python # -*- coding: utf-8 -*- # http://www.cnblogs.com/liu-ke/import wmiimport osimport sysimport platformimport time#还需要安装一个模块pywin32,要不会报错## def sys_version():#     c = wmi.WMI()#     # 获取操作系统版本#     for sys in c.Win32_OperatingSystem():#         print("Version:%s" % sys.Caption.encode("UTF8"), "Vernum:%s" % sys.BuildNumber)#         print(sys.OSArchitecture.encode("UTF8"))  # 系统是32位还是64位的#         print(sys.NumberOfProcesses)  # 当前系统运行的进程总数### # c = wmi.WMI()# # for i in c.classes:# #       if "operatingsystem" in i.lower():# #         print (i)# # print(c.__doc__)### def cpu_mem():#     c = wmi.WMI()#     # CPU类型和内存#     for processor in c.Win32_Processor():#         # print "Processor ID: %s" % processor.DeviceID#         print("Process Name: %s" % processor.Name.strip())#     for Memory in c.Win32_PhysicalMemory():#         print("Memory Capacity: %.fMB" % (int(Memory.Capacity) / 1048576))### def cpu_use():#     # 5s取一次CPU的使用率#     c = wmi.WMI()#     while True:#         for cpu in c.Win32_Processor():#             timestamp = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())#             print('%s | Utilization: %s: %d %%' % (timestamp, cpu.DeviceID, cpu.LoadPercentage))#             time.sleep(5)### def disk():#     c = wmi.WMI()#     # 获取硬盘分区#     for physical_disk in c.Win32_DiskDrive():#         for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):#             for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):#                 print(physical_disk.Caption.encode("UTF8"), partition.Caption.encode("UTF8"), logical_disk.Caption)##                 # 获取硬盘使用百分情况#     for disk in c.Win32_LogicalDisk(DriveType=3):#         print(disk.Caption, "%0.2f%% free" % (100.0 * len(disk.FreeSpace) / len(disk.Size)))def network():    c = wmi.WMI()    # 获取MAC和IP地址    for interface in c.Win32_NetworkAdapterConfiguration(IPEnabled=1):        print("MAC: %s" % interface.MACAddress)    for ip_address in interface.IPAddress:        print("ip_add: %s" % ip_address)    print("IPV4地址为: " + interface.IPAddress[0])    print("IPV6地址为: " + interface.IPAddress[1])    # # 获取自启动程序的位置    # for s in c.Win32_StartupCommand():    #     print("[%s] %s <%s>" % (s.Location.encode("UTF8"), s.Caption.encode("UTF8"), s.Command.encode("UTF8")))        # 获取当前运行的进程    # for process in c.Win32_Process():    #     print(process.ProcessId, process.Name)def main():    # sys_version()    # cpu_mem()    # disk()    network()    # cpu_use()if __name__ == '__main__':    main()    # print(platform.system())    # print(platform.release())    # print(platform.version())    # print(platform.platform())    # print(platform.machine())

 

转载于:https://www.cnblogs.com/Anec/p/9581926.html

你可能感兴趣的文章
java_基础语法之while语句
查看>>
个人经验 - Android的RelativeLayout布局的layout_height属性设置为wrap_content时的坑
查看>>
最长子序列
查看>>
SQL分组查询每组前几条数据
查看>>
01章 面向对象开发方法概述
查看>>
命令行调用Lame批量压缩MP3
查看>>
iis7配置网站容易出现的问题(转)
查看>>
如何成为一名优秀的程序员?
查看>>
HDU(4528),BFS,2013腾讯编程马拉松初赛第五场(3月25日)
查看>>
C++期中考试
查看>>
Working with Characters and Strings(Chapter 2 of Windows Via C/C++)
查看>>
vim中文帮助教程
查看>>
Android 创建与解析XML(四)—— Pull方式
查看>>
CodeForces 411B 手速题
查看>>
同比和环比
查看>>
美国在抛弃慕课,中国却趋之若鹜
查看>>
SpringMvc拦截器运行原理。
查看>>
MySQL基础3
查看>>
逻辑斯蒂回归(Logistic Regression)
查看>>
360前端面试题 2015年 07
查看>>