Python-written script to detect Windows System Information with WMI

Source: Internet
Author: User
Tags print print

The script is as follows:

#!/usr/bin/Env Python#coding:utf-8Import wmiimport sys,time,platformdef get_system_info (OS):"""gets the operating system version. """Print Print"Operating System:"    ifOS = ="Windows": C=WMI. WMI () forSysinchC.win32_operatingsystem (): Print'\ t'+"Version: \t%s"% sys. Caption.encode ("UTF-8") Print'\ t'+"vernum: \t%s"%sys. Buildnumberdef get_memory_info (OS):"""gets the physical memory and virtual memory. """Print Print"Memory_info:"    ifOS = ="Windows": C=WMI. WMI () CS=C.win32_computersystem () pfu=c.win32_pagefileusage () memtotal=int(cs[0]. TotalPhysicalMemory)/1024x768/1024x768Print'\ t'+"TotalPhysicalMemory:"+'\ t'+ STR (memtotal) +"M"#tmpdict ["Memfree"] =int(os[0]. Freephysicalmemory)/1024x768Swaptotal=int(pfu[0]. allocatedbasesize) Print'\ t'+"swaptotal:"+'\ t'+ STR (swaptotal) +"M"#tmpdict ["Swapfree"] =int(pfu[0]. allocatedbasesize-pfu[0]. Currentusage) def get_disk_info (OS):"""Gets the physical disk information. """Print Print"Disk_info:"    ifOS = ="Windows": Tmplist=[] C=WMI. WMI () forPhysical_diskinchc.win32_diskdrive ():ifPhysical_disk. Size:print'\ t'+ STR (physical_disk. Caption) +': \ t'+ STR (Long(Physical_disk. Size)/1024x768/1024x768/1024x768) +"G"def get_cpu_info (OS):"""gets the CPU information. """Print Print"Cpu_info:"    ifOS = ="Windows": Tmpdict={} tmpdict["Cpucores"] =0C=WMI. WMI () forCpuinchc.win32_processor (): tmpdict["Cputype"] =CPU. NameTry: tmpdict["Cpucores"] =CPU. NumberOfCores except:tmpdict["Cpucores"] +=1tmpdict["Cpuclock"] =CPU. MaxClockSpeed Print'\ t'+'cputype: \ t'+ STR (tmpdict["Cputype"]) Print'\ t'+'cpucores: \ t'+ STR (tmpdict["Cpucores"]) def get_network_info (OS):"""gets the NIC information and the current number of TCP connections. """Print Print"Network_info:"    ifOS = ="Windows": Tmplist=[] C=WMI. WMI () for Interface inchC.win32_networkadapterconfiguration (ipenabled=1): Tmpdict={} tmpdict["Description"] =Interface. Description tmpdict["IPAddress"] =Interface. ipaddress[0] tmpdict["ipsubnet"] =Interface. ipsubnet[0] tmpdict["MAC"] =Interface. MACAddress tmplist.append (tmpdict) forIinchTmplist:print'\ t'+ i["Description"] Print'\ t'+'\ t'+"MAC:"+'\ t'+ i["MAC"] Print'\ t'+'\ t'+"IPAddress:"+'\ t'+ i["IPAddress"] Print'\ t'+'\ t'+"ipsubnet:"+'\ t'+ i["ipsubnet"]         forInterfaceperftcpinchC.win32_perfrawdata_tcpip_tcpv4 (): Print'\ t'+'TCP Connect: \ t'+Str (interfaceperftcp.connectionsestablished)if__name__ = ="__main__": OS=Platform.system () get_system_info (OS) get_memory_info (OS) get_disk_info (OS) get_cpu_info (OS) get_netwo Rk_info (OS)

Execution Result:

Operating System:Version:Microsoft WindowsTenHome Chinese version vernum:15063memory_info:totalphysicalmemory:4011m Swaptotal:6656mdisk_info:toshiba mq01abf050:465g KI Ngston Sa400s37120g:111gcpu_info:cputype:intel (R) Core (TM) i5-5257UCPU @2. 70GHz cpucores:2Network_info:realtek rtl8723be Wireless LAN802.11n pci-E NIC MAC: -: 6d:c7:8d: -: 8D IPAddress:192.168.0.103ipsubnet:255.255.255.0TCP Connect: Wu

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

Python-written script to detect Windows System Information with WMI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.