利用python写一段读取电脑配置信息的程序
发布网友
发布时间:2022-04-26 21:15
我来回答
共1个回答
热心网友
时间:2022-04-18 05:39
主要利用python的wmi模块,提供非常多的信息。
import wmi
def sys_version():
c = wmi.WMI()
# 操作系统版本,版本号,32位/64位
print('\nOS:')
sys = c.Win32_OperatingSystem()[0]
print(sys.Caption, sys.BuildNumber, sys.OSArchitecture)
# CPU类型 CPU内存
print('\nCPU:')
processor = c.Win32_Processor()[0]
print(processor.Name.strip())
Memory = c.Win32_PhysicalMemory()[0]
print(int(Memory.Capacity)//1048576,'M')
# 硬盘名称,硬盘剩余空间,硬盘总大小
print('\nDISK:')
for disk in c.Win32_LogicalDisk(DriveType=3):
print(disk.Caption,'free:', int(disk.FreeSpace)//1048576,'M\t', 'All:', int(disk.Size)//1048576,'M')
# 获取MAC和IP地址
print('\nIP:')
for interface in c.Win32_NetworkAdapterConfiguration(IPEnabled=1):
print("MAC: %s" % interface.MACAddress)
for ip_address in interface.IPAddress:
print("\tIP: %s" % ip_address)
# BIOS版本 生产厂家 释放日期
print('\nBIOS:')
bios = c.Win32_BIOS()[0]
print(bios.Version)
print(bios.Manufacturer)
print(bios.ReleaseDate)
sys_version()
显示:
OS:
Microsoft Windows 10 专业版 17134 64 位
CPU:
Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz
8192 M
DISK:
C: free: 34165 M All: 120825 M
D: free: 265648 M All: 390777 M
E: free: 35669 M All: 204796 M
F: free: 5814 M All: 28163 M
G: free: 328650 M All: 329999 M
IP:
MAC: 00:50:56:C0:00:01
IP: 192.168.182.1
IP: fe80::e0fb:efd8:ecb0:77f4
MAC: 00:50:56:C0:00:08
IP: 192.168.213.1
IP: fe80::8da1:ce76:dae:bd48
MAC: 54:E1:AD:77:57:AB
IP: 192.168.199.105
IP: fe80::aca8:4e6f:46e7:ef4a
BIOS:
LENOVO - 1
LENOVO
20170518000000.000000+000