Python 通过wmi获取Window服务器硬件信息
通过pip install wmi安装wmi
查看cpu序列号:
wmic cpu get processorid

查看主板序列号:
wmic baseboard get serialnumber

查看网卡信息:
wmic nicconfig get macaddress

通过Python获取
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys
import wmi
c = wmi.WMI()
# 处理器
def printCPU():
tmpdict = {}
tmpdict["CpuCores"] = 0
for cpu in c.Win32_Processor():
tmpdict["cpuid"] = cpu.ProcessorId.strip()
tmpdict["CpuType"] = cpu.Name
tmpdict['systemName'] = cpu.SystemName
try:
tmpdict["CpuCores"] = cpu.NumberOfCores
except:
tmpdict["CpuCores"] += 1
tmpdict["CpuClock"] = cpu.MaxClockSpeed
tmpdict['DataWidth'] = cpu.DataWidth
print (tmpdict)
return tmpdict
# 主板
def printMain_board():
boards = []
# print len(c.Win32_BaseBoard()):
for board_id in c.Win32_BaseBoard():
tmpmsg = {}
tmpmsg['UUID'] = board_id.qualifiers['UUID'][1:-1] # 主板UUID,有的主板这部分信息取到为空值,ffffff-ffffff这样的
tmpmsg['SerialNumber'] = board_id.SerialNumber # 主板序列号
tmpmsg['Manufacturer'] = board_id.Manufacturer # 主板生产品牌厂家
tmpmsg['Product'] = board_id.Product # 主板型号
boards.append(tmpmsg)
print (boards)
return boards
# BIOS
def printBIOS():
bioss = []
for bios_id in c.Win32_BIOS():
tmpmsg = {}
tmpmsg['BiosCharacteristics'] = bios_id.BiosCharacteristics # BIOS特征码
tmpmsg['version'] = bios_id.Version # BIOS版本
tmpmsg['Manufacturer'] = bios_id.Manufacturer.strip() # BIOS固件生产厂家
tmpmsg['ReleaseDate'] = bios_id.ReleaseDate # BIOS释放日期
tmpmsg['SMBIOSBIOSVersion'] = bios_id.SMBIOSBIOSVersion # 系统管理规范版本
bioss.append(tmpmsg)
print (bioss)
return bioss
# 硬盘
def printDisk():
disks = []
for disk in c.Win32_DiskDrive():
# print disk.__dict__
tmpmsg = {}
tmpmsg['SerialNumber'] = disk.SerialNumber.strip()
tmpmsg['DeviceID'] = disk.DeviceID
tmpmsg['Caption'] = disk.Caption
tmpmsg['Size'] = disk.Size
tmpmsg['UUID'] = disk.qualifiers['UUID'][1:-1]
disks.append(tmpmsg)
for d in disks:
print (d)
return disks
# 内存
def printPhysicalMemory():
memorys = []
for mem in c.Win32_PhysicalMemory():
tmpmsg = {}
tmpmsg['UUID'] = mem.qualifiers['UUID'][1:-1]
tmpmsg['BankLabel'] = mem.BankLabel
tmpmsg['SerialNumber'] = mem.SerialNumber.strip()
# tmpmsg['ConfiguredClockSpeed'] = mem.ConfiguredClockSpeed
tmpmsg['Capacity'] = mem.Capacity
# tmpmsg['ConfiguredVoltage'] = mem.ConfiguredVoltage
memorys.append(tmpmsg)
for m in memorys:
print (m)
return memorys
# 电池信息,只有笔记本才会有电池选项
def printBattery():
isBatterys = False
for b in c.Win32_Battery():
isBatterys = True
return isBatterys
# 网卡mac地址:
def printMacAddress():
macs = []
for n in c.Win32_NetworkAdapter():
mactmp = n.MACAddress
if mactmp and len(mactmp.strip()) > 5:
tmpmsg = {}
tmpmsg['MACAddress'] = n.MACAddress
tmpmsg['Name'] = n.Name
tmpmsg['DeviceID'] = n.DeviceID
tmpmsg['AdapterType'] = n.AdapterType
tmpmsg['Speed'] = n.Speed
macs.append(tmpmsg)
print (macs)
return macs
def main():
printCPU()
printMain_board()
printBIOS()
printDisk()
printPhysicalMemory()
printMacAddress()
printBattery()
if __name__ == '__main__':
main()

Python 通过wmi获取Window服务器硬件信息的更多相关文章
- Python使用wmi获取Windows相关信息
在使用Python获取Windows系统上的相关的信息可以使用WMI接口来获取, 什么是wmi? WMI是一项核心的Windows管理技术,WMI作为一种规范和基础结构,通过它可以访问.配置.管理和监 ...
- Python 通过dmidecode获取Linux服务器硬件信息
通过 dmidecode 命令可以获取到 Linux 系统的包括 BIOS. CPU.内存等系统的硬件信息,这里使用 python 代码来通过调用 dmidecode 命令来获取 Linux 必要的系 ...
- 通过wmi获取本地硬件信息的一些疑问。
通过wmi获取本地硬件信息的一些疑问. http://bbs.csdn.net/topics/391017789 http://blog.csdn.net/xcntime/article/detail ...
- 用PYTHON + PYWIN32 + WMI获取WINDOWS系统基本信息
网上原码,去了DECODE编码的问题. PyScripter这个PYTHON的IDE工具在WIN下表现不错哟. 感觉比SPYDER,ERIC,SUBLEME TEXT3之类的好用呀.. #!/usr/ ...
- 利用python 与 wmi 获取WINDOWS基本信息
#!/usr/bin/env python3.5 # -*- coding:utf8 -*- import platform import subprocess import wmi def serv ...
- Python基础:获取平台相关信息
Windows 10家庭中文版,Python 3.6.4, 本文介绍了使用os.platform.sys三个模块获取Python程序的运行平台相关的信息. os模块:提供 各种各样的操作系统接口 os ...
- C++ WMI获取系统硬件信息(CPU/DISK/NetWork etc)
官网找到一个例子,根据例子修改下可以获取很多信息 #define _WIN32_DCOM #include <iostream> using namespace std; #include ...
- python开发_platform_获取操作系统详细信息工具
''' python中,platform模块给我们提供了很多方法去获取操作系统的信息 如: import platform platform.platform() #获取操作系统名称及版本号,'Win ...
- c# WMI获取机器硬件信息(硬盘,cpu,内存等)
using System; using System.Collections.Generic; using System.Globalization; using System.Management; ...
随机推荐
- React 项目中修改 Ant Design 的默认样式(Input Checkbox 等等
修改样式更符合项目的需求特别是在 Input 和 Checkbox 等等一系列 试过很的方式都有问题, 比如直接在行内添加样式会无法传递到特定的层级 最好的办法是添加 id 可行 渲染部分代码 < ...
- (74)c++再回顾一继承和派生
一:继承和派生 0.默认构造函数即不带参数的构造函数或者是系统自动生成的构造函数.每一个类的构造函数可以有多个,但是析构函数只能有一个. 1.采用公用public继承方式,则基类的公有成员变量和成员函 ...
- 1.Python编程基础
1. 其实,程序指的就是一系列指令,用来告诉计算机做什么,而编写程序的关键在于,我们需要用计算机可以理解的语言来提供这些指令. 虽然借助 Siri(Apple).Google Now(Android) ...
- Oracle生成ASH报告
1.ASH (Active SessionHistory) ASH以V$SESSION为基础,每秒采样一次,记录活动会话等待的事件.不活动的会话不会采样,采样工作由新引入的后台进程MMNL来完成. v ...
- 为Sublime Text 3设置优雅的字体
本文使用的Sublime Text 3版本是3.2.1(build 3207),这个版本默认对中文的支持很糟糕,中国程序员很费眼睛,需要做一番设置. 首选需要在本机安装漂亮的字体,我们选用的是YaHe ...
- bootstrap 讲解(中)
bootstrap:常用于后台开发,如学生管理系统,虽然稍显笨重,但也是一个开发的利器 推荐下载 3.3.7 版本 也可下载最新版4.3.1 (最新版在手机端不起效果) 且依赖 jQuery 的封装库 ...
- 如何在maven项目中引用领一个项目
1 有两个项目 maven01 和maven 02,想在maven 02中引用maven01的方法,该如何操作呢 maven01中Factory类中的方法 public class Factory ...
- gson转换json到bean时重命名
@Expose @SerializedName("0001") public Map<String,ChannelBean> c0001 = new HashMap ...
- Web.Config全攻略
一.认识Web.config文件 Web.config 文件是一个xml文本文件,它用来储存 asp.NET Web 应用程序的配置信息(如最常用的设置asp.NET Web 应用程序的身份验证方 ...
- 在VSCode中开启ESLint风格审查
最近一直在学习开发一个VUE项目,几乎没有前端基础摸爬滚打,就一边摸索HTML,JS,CSS一边模仿着已有代码开发,也还算能学到东西. VSCode确实还不错,很轻量.在刚开始学写vue的时候,后台总 ...