Python 获取本地主机信息
import wmi c = wmi.WMI() for sys in c.Win32_OperatingSystem(): #系统信息 print(sys.Caption) #系统版本号 print(sys.BuildNumber) #32/64位 print(sys.OSArchitecture) #当前系统进程数 print(sys.NumberOfProcesses) #处理器信息 for pro in c.win32_Processor(): print(pro.DeviceID) print(pro.Name.strip()) #内存信息 for Memory in c.Win32_PhysicalMemory(): print((int(Memory.Capacity)/1048576)) # 获取硬盘分区 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, partition.Caption, logical_disk.Caption) # 获取硬盘使用百分情况 for disk in c.Win32_LogicalDisk(DriveType=3): print(disk.Caption, "%0.2f%% free" % (100.0 * int(disk.FreeSpace) / int(disk.Size))) 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) # 获取自启动程序的位置 for s in c.Win32_StartupCommand(): print("[%s] %s <%s>" % (s.Location, s.Caption, s.Command)) # 获取当前运行的进程 for process in c.Win32_Process(): print((process.ProcessId, process.Name))