代码片段(2)
[代码] [Python]代码
01 | # -*- coding:gb2312 -*- |
02 | import wmi |
03 | hardware = file ( 'F:\Python\Hardware.txt' , 'w' ) |
04 |
05 | w = wmi.WMI() |
06 | hardware.write( "cpu型号,主频:\n" ) |
07 | for processor in w.Win32_Processor(): |
08 | hardware.write( "Processor ID: %s" % processor.DeviceID) |
09 | hardware.write( "\nProcess Name: %s" % processor.Name.strip() + '\n\n' ) |
10 | hardware.write( '内存大小:' ) |
11 | totalMemSize = 0 |
12 | for memModule in w.Win32_PhysicalMemory(): |
13 | totalMemSize + = int (memModule.Capacity) |
14 | hardware.write( "\nMemory Capacity: %.2fMB" % ((totalMemSize + 1048575 ) / 1048576 ) + '\n\n' ) |
15 | hardware.write( '硬盘使用情况:' ) |
16 | for disk in w.Win32_LogicalDisk (DriveType = 3 ): |
17 | temp = disk.Caption + " %0.2f%% free" % ( 100.0 * long (disk.FreeSpace) / long (disk.Size)) |
18 | hardware.write( '\n' + temp) |
19 | hardware.write( '\n' ) |
20 | hardware.write( '\n显示IP和MAC:\n' ) |
21 | for interface in w.Win32_NetworkAdapterConfiguration (IPEnabled = 1 ): |
22 | hardware.write( '网卡驱动信息:' ) |
23 | hardware.write(interface.Description + '\n' ) |
24 | hardware.write( '网卡MAC地址:' ) |
25 | hardware.write(interface.MACAddress + '\n' ) |
26 | #for ip_address in interface.IPAddress: |
27 | hardware.write( 'IP地址:' ) |
28 | hardware.write(interface.IPAddress[ 0 ] + '\n' ) |
29 | hardware.write( '外网IP接口' ) |
30 | hardware.write(interface.IPAddress[ 1 ] + '\n' ) |
31 | hardware.close() |
[图片] 硬件信息.png
![](http://static.oschina.net/uploads/code/201304/15134056_1xpp.png)