Python obtains local hardware information

Source: Internet
Author: User
Note: This Code requires support for wmi and system win32 extensions. Without the installation library to download the installation, I installed WMI-1.4.6.win32 and pywin32-218.win32-py2.7... note: this code requires wmi and system win32 extension support.

No installation library to download the installation, I installed WMI-1.4.6.win32 and pywin32-218.win32-py2.7

Also, modify the file directory in the code.

#-*-Coding: gb2312-*-import wmihardware = file ('F: \ Python \ Hardware.txt ', 'w') w = wmi. WMI () hardware. write ("cpu model, clock speed: \ n") for processor in w. win32_Processor (): hardware. write ("Processor ID: % s" % processor. deviceID) hardware. write ("\ nProcess Name: % s" % processor. name. strip () + '\ n \ n') hardware. write ('memory size: ') totalMemSize = 0for memModule in w. win32_PhysicalMemory (): totalMemSize + = int (memModule. capacity) hardware. write ("\ nMemory Capacity: %. 2fMB "% (totalMemSize + 1048575)/1048576) + '\ n \ n') hardware. write ('Hard disk usage: ') for disk in w. win32_LogicalDisk (DriveType = 3): temp = disk. caption + "% 0.2f % free" % (100.0 * long (disk. freeSpace)/long (disk. size) hardware. write ('\ n' + temp) hardware. write ('\ n') hardware. write ('\ n display IP address and MAC: \ n') for interface in w. win32_NetworkAdapterConfiguration (IPEnabled = 1): hardware. write ('Nic driver information: ') hardware. write (interface. description + '\ n') hardware. write ('Nic MAC address: ') hardware. write (interface. MACAddress + '\ n') # for ip_address in interface. IPAddress: hardware. write ('IP Address: ') hardware. write (interface. IPAddress [0] + '\ n') hardware. write ('internet IP interface ') hardware. write (interface. IPAddress [1] + '\ n') hardware. close ()

Run

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.