Python uses the WMI module to get the windows system information

install vmi

https://pypi.org/project/WMI/#history

 

The script is as follows:

#!/usr/bin/env python
#coding:utf-8



import wmi
import them
import sys
import platform
import time

def sys_version():
    c = wmi.WMI ()
    #Get OS version
    for sys in c.Win32_OperatingSystem():
        print "Version:%s" % sys.Caption.encode("UTF8"),"Vernum:%s" % sys.BuildNumber
        print sys.OSArchitecture.encode( " UTF8 " )# Whether the system is 32-bit or 64-bit
        print sys.NumberOfProcesses #The total number of processes running on the current system

def cpu_mem():
    c = wmi.WMI ()
    #CPU type and memory
    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 Get the usage of the CPU once
    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 ()
    #Get the hard disk partition
    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

    #Get the percentage of hard disk usage
    for disk in c.Win32_LogicalDisk (DriveType=3):
        print disk.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size))

def network():
    c = wmi.WMI ()
    #Get MAC and IP address
    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

    #Get the location of the self-starting program
    for s in c.Win32_StartupCommand ():
        print "[%s] %s <%s>" % (s.Location.encode("UTF8"), s.Caption.encode("UTF8"), s.Command.encode("UTF8"))


    #Get the currently running process
    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()

 

Results of the:

Version: Microsoft Windows 10 Home Chinese Vernum: 15063 
64 -bit
 155
Windows
10
10.0.15063
Windows-10-10.0.15063
AMD64

 

 

Reference: http://blog.51cto.com/wangwei007/1158075

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325461084&siteId=291194637