|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
小知识:CentOS从来就不是一个人的独角戏,也许CentOS会有分叉或名称变更的危险,但决不能说它接近死亡。闲来无聊,用python写了一个检测windows体系硬件信息的剧本,重要就是用WMI模块来完成,分享给人人,愿望对人人有所赞助。linux的体系信息直接用shell便可获得,这里不做引见。获得重要检测内容为:体系平台,内存,硬盘硬件信息(具体的之前写了一个,人人参考),CPU信息,网卡信息等。
- #!/usr/bin/envpython#-*-coding:utf-8-*-importwmiimportsys,time,platformdefget_system_info(os):"""获得操作体系版本。"""printprint"Operatingsystem:"ifos=="Windows":c=wmi.WMI()forsysinc.Win32_OperatingSystem():print +"Version: %s"%sys.Caption.encode("GBK")print +"Vernum: %s"%sys.BuildNumberdefget_memory_info(os):"""获得物理内存和虚拟内存。"""printprint"memory_info:"ifos=="Windows":c=wmi.WMI()cs=c.Win32_ComputerSystem()pfu=c.Win32_PageFileUsage()MemTotal=int(cs[0].TotalPhysicalMemory)/1024/1024print +"TotalPhysicalMemory:"+ +str(MemTotal)+"M"#tmpdict["MemFree"]=int(os[0].FreePhysicalMemory)/1024SwapTotal=int(pfu[0].AllocatedBaseSize)print +"SwapTotal:"+ +str(SwapTotal)+"M"#tmpdict["SwapFree"]=int(pfu[0].AllocatedBaseSize-pfu[0].CurrentUsage)defget_disk_info(os):"""获得物理磁盘信息。"""printprint"disk_info:"ifos=="Windows":tmplist=[]c=wmi.WMI()forphysical_diskinc.Win32_DiskDrive():ifphysical_disk.Size:print +str(physical_disk.Caption)+: +str(long(physical_disk.Size)/1024/1024/1024)+"G"defget_cpu_info(os):"""获得CPU信息。"""printprint"cpu_info:"ifos=="Windows":tmpdict={}tmpdict["CpuCores"]=0c=wmi.WMI()forcpuinc.Win32_Processor():tmpdict["CpuType"]=cpu.Nametry:tmpdict["CpuCores"]=cpu.NumberOfCoresexcept:tmpdict["CpuCores"]+=1tmpdict["CpuClock"]=cpu.MaxClockSpeedprint +CpuType: +str(tmpdict["CpuType"])print +CpuCores: +str(tmpdict["CpuCores"])defget_network_info(os):"""获得网卡信息和以后TCP衔接数。"""printprint"network_info:"ifos=="Windows":tmplist=[]c=wmi.WMI()forinterfaceinc.Win32_NetworkAdapterConfiguration(IPEnabled=1):tmpdict={}tmpdict["Description"]=interface.Descriptiontmpdict["IPAddress"]=interface.IPAddress[0]tmpdict["IPSubnet"]=interface.IPSubnet[0]tmpdict["MAC"]=interface.MACAddresstmplist.append(tmpdict)foriintmplist:print +i["Description"]print + +"MAC:"+ +i["MAC"]print + +"IPAddress:"+ +i["IPAddress"]print + +"IPSubnet:"+ +i["IPSubnet"]forinterfacePerfTCPinc.Win32_PerfRawData_Tcpip_TCPv4():print +TCPConnect: +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_network_info(os)
复制代码 小知识:CentOS是基于RedHatEnterpriseLinux(收费昂贵但口碑极佳)的源代码再编译出来的免费版,因此不仅继承RHEL优越的稳定性,还提供免费更新, |
|