注意:这段代码需要wmi 和 系统 win32 扩展支持。
没安装库的要先下载安装,我装的是 WMI-1.4.6.win32 和 pywin32-218.win32-py2.7
还有,代码里面文件目录自己修改下咯。
# -*- coding:gb2312 -*-
import wmi
hardware=file('F:\Python\Hardware.txt','w')
w=wmi.WMI()
hardware.write("cpu型号,主频:\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('内存大小:')
totalMemSize=0
for memModule in w.Win32_PhysicalMemory():
totalMemSize+=int(memModule.Capacity)
hardware.write("\nMemory Capacity: %.2fMB" %((totalMemSize+1048575)/1048576)+'\n\n')
hardware.write('硬盘使用情况:')
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显示IP和MAC:\n')
for interface in w.Win32_NetworkAdapterConfiguration (IPEnabled=1):
hardware.write('网卡驱动信息:')
hardware.write(interface.Description+'\n')
hardware.write('网卡MAC地址:')
hardware.write(interface.MACAddress+'\n')
#for ip_address in interface.IPAddress:
hardware.write('IP地址:')
hardware.write(interface.IPAddress[0]+'\n')
hardware.write('外网IP接口')
hardware.write(interface.IPAddress[1]+'\n')
hardware.close()运行效果图
SiteTeam企业自助建站软件是一部专业为搜索引擎营销(网站优化/SEO)而设计,操作极简单,网站极稳定、故障自动修复、在线升级维护、建站速度极快、专为大众上网营销而设计的完全免费开源企业建站系统! 1)专为搜索引擎排名而设计。很容易获得较好的搜索引擎排名,也就是说,你通过本网站系统构建起来的企业网站,并用它发布的信息是非常容易获得较好的搜索引擎排名(关于这点,已经有大量的案例)。 2)超简单配
0

立即学习“Python免费学习笔记(深入)”;
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号