python - wmi模块学习(windwos硬件信息获取)
获取windows操作系统的硬件信息
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# http://www.cnblogs.com/liu-ke/
import wmi
import os
import sys
import platform
import 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())
python - wmi模块学习(windwos硬件信息获取)的更多相关文章
- python wmi模块学习
# -*- coding: cp936 -*- import wmi c = wmi.WMI () for sys in c.Win32_OperatingSystem(): print " ...
- python - argparse 模块学习
python - argparse 模块学习 设置一个解析器 使用argparse的第一步就是创建一个解析器对象,并告诉它将会有些什么参数.那么当你的程序运行时,该解析器就可以用于处理命令行参数. 解 ...
- python paramiko模块学习分享
python paramiko模块学习分享 paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.paramiko支持Linux, Sola ...
- Python time模块学习
Python time模块提供了一些用于管理时间和日期的C库函数,由于它绑定到底层C实现,因此一些细节会基于具体的平台. 一.壁挂钟时间 1.time() time模块的核心函数time(),它返回纪 ...
- windows linux—unix 跨平台通信集成控制系统----系统硬件信息获取
控制集成系统需要了解系统的各项硬件信息,之前我们设计的时候,习惯使用c函数来搞,后来可能发现程序的移植性收到了一些影响,比如unix内核的一些c函数在linux下面是没有的: 比如 苹果达尔文内核的如 ...
- Python logging 模块学习
logging example Level When it's used Numeric value DEBUG Detailed information, typically of interest ...
- python atexit模块学习
python atexit模块 只定义了一个register模块用于注册程序退出时的回调函数,我们可以在这个函数中做一下资源清理的操作 注:如果程序是非正常crash,或者通过os._exit()退出 ...
- python os模块学习
一.os模块概述 Python os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的. 二.常用方法 1.os.name 输出字符串指示正在使用的平台.如果是wi ...
- python logging模块学习(转)
前言 日志是非常重要的,最近有接触到这个,所以系统的看一下Python这个模块的用法.本文即为Logging模块的用法简介,主要参考文章为Python官方文档,链接见参考列表. 另外,Python的H ...
随机推荐
- mysql5.7 rpm安装教程
注意版本和此次更新时间 2017-12-03 版本:mysql-5.7.20-1.el6.x86_64 环境:linux6.x 官方下载地址: wget https://dev.mysql.co ...
- POSIX 线程取消点的 Linux 实现
http://blog.csdn.net/stevenliyong/article/details/4364039 原文链接:http://blog.solrex.cn/articles/linux- ...
- 2019.3.18考试&2019.3.19考试&2019.3.21考试
2019.3.18 C O D E T1 树上直接贪心,环上for一遍贪心 哇说的简单,码了将近一下午终于码出来了 感觉自己码力/写题策略太糟糕了,先是搞了一个细节太多的写法最后不得不弃疗了,然后第二 ...
- CF 987
毒瘤啊啊啊啊啊 虽然排名还不错,331,但是B我没做出来...... 这是战绩: 可以看到我大发神威势如破竹的A了CDE,但是B把我卡了三次...不然我就能进前300了(还是很水). 逐一分析题目: ...
- win10下通过Anaconda安装TensorFlow-GPU1.3版本,并配置pycharm运行Mnist手写识别程序
折腾了一天半终于装好了win10下的TensorFlow-GPU版,在这里做个记录. 准备安装包: visual studio 2015: Anaconda3-4.2.0-Windows-x86_64 ...
- Junit测试的理解------java基础知识
前言:不知道是最近懒了,还不不想认真写博客,其实写一个质量高的博客是需要时间的,没办法时间太紧了 package com.mon11.day13.linkedlist; import static o ...
- 安装使用hibernate tools
help-Eclipse marketplace-hibernate(搜索)-jboss tools(安装)
- CentOS 使用 Xfce 桌面并通过 xrdp 登录
基础环境 CentOS 7.1 最小化安装 安装步骤 以下步骤,均通过ssh连接到主机进行操作. 安装桌面支持 首先安装桌面支持 yum groupinstall "Server with ...
- javascript 模拟日历
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- JAVA记录-redis缓存机制介绍(三)
Redis 事务 Redis 事务可以一次执行多个命令, 并且带有以下两个重要的保证: 事务是一个单独的隔离操作:事务中的所有命令都会序列化.按顺序地执行.事务在执行的过程中,不会被其他客户端发送来的 ...