基于wmi module获取windows服务器配置信息

闲来无事,写一个简单的python脚本来看看本地电脑的配置。

1、环境准备

pip install wmi

2、实用脚本(win_info.py)

脚本内容如下:

#python3:pip install wmi
import wmi
import os
import socket

w = wmi.WMI()
'''
Win32_Processor 查CPU
Win32_ComputerSystem 查内存
Win32_LogicalDisk 查硬盘
'''

#获取计算机名称和IP
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
#print("计算机名称: %s" %hostname)
print("IP地址: %s" %ip)

#获取电脑使用者信息
for CS in w.Win32_ComputerSystem():
  	#print(CS)
	print("电脑名称: %s" %CS.Caption)
	print("使用者: %s" %CS.UserName)
	print("制造商: %s" %CS.Manufacturer)
	print("系统信息: %s" %CS.SystemFamily)
	print("工作组: %s" %CS.Workgroup)
	print("机器型号: %s" %CS.model)
	print("")
#获取操作系统信息
for OS in w.Win32_OperatingSystem():
    #print(OS)
    print("操作系统: %s" %OS.Caption)
    print("语言版本: %s" %OS.MUILanguages)
    print("系统位数: %s" %OS.OSArchitecture)
    print("注册人: %s" %OS.RegisteredUser)
    print("系统驱动: %s" %OS.SystemDevice)
    print("系统目录: %s" %OS.SystemDirectory)
    print("")
#获取电脑IP和MAC信息
for address in w.Win32_NetworkAdapterConfiguration(ServiceName = "e1dexpress"):
    #print(address)
    print("IP地址: %s" % address.IPAddress)
    print("MAC地址: %s" % address.MACAddress)
    print("网络描述: %s" % address.Description)
    print("")
#获取电脑CPU信息
#https://docs.microsoft.com/zh-cn/windows/win32/cimwin32prov/win32-processor?redirectedfrom=MSDN
for cpu in w.Win32_Processor():
    #print(processor)
    print("CPU型号: %s" % cpu.Name.strip())
    print("CPU核数: %s" % cpu.NumberOfCores) #处理器的当前实例的数目
    print("逻辑CPU:%s" % cpu.NumberOfLogicalProcessors)
    print("")
#获取BIOS信息
for BIOS in w.Win32_BIOS():
    #print(BIOS)
    print("使用日期: %s" %BIOS.Description)
    print("主板型号: %s" %BIOS.SerialNumber)
    print("当前语言: %s" %BIOS.CurrentLanguage)
    print("")
#获取内存信息
totalMemSize=0
for mem in w.Win32_PhysicalMemory():
    totalMemSize += int(mem.Capacity)
print("内存厂商: %s" %mem.Manufacturer)
print("内存型号: %s" %mem.PartNumber)
print("内存大小: %.2fGB" %(totalMemSize/1024**3))
print("")
#获取磁盘信息
for disk in w.Win32_DiskDrive():
    diskSize = int(disk.size)
    print("磁盘名称: %s" %disk.Caption)
    print("硬盘型号: %s" %disk.Model)
    print("磁盘大小: %.2fGB" %(diskSize/1024**3))
#获取显卡信息
for xk in w.Win32_VideoController():
    print("显卡名称: %s" %xk.name)
    print("")

#获取进程信息
print("进程信息:")
for process in w.Win32_Process():
	print("%5s  %s" %(process.ProcessId, process.Name))

在这里插入图片描述

3、输出结果

输出结果如下:
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

淡定波007

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值