python如何获取服务器硬件信息
本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下
#!/usr/bin/envpython
#-*-coding:utf-8-*-
importrlcompleter,readline
readline.parse_and_bind('tab:complete')
importdmidecode
importtime
importos
importre
system=dmidecode.system()
print"\033[1;36;40m%s\033[0m"%"获取服务器硬件信息"
forx,yinsystem.items():
foriiny['data'].items():
ifi[0]=='ProductName':
print"\033[1;31;40m%s\033[0m"%"-"*10
print'Servermodels:%s'%i[1]
printi
print"\033[1;36;40m%s\033[0m"%"获取服务器CPU信息"
forx,yindmidecode.processor().items():
form,niny.items():
ifm=='data':
print"\033[1;31;40m%s\033[0m"%"-"*10
forx,yinn.items():
printx,y
print"\033[1;36;40m%s\033[0m"%"获取服务器BIOS信息"
forx,yindmidecode.bios().items():
form,niny['data'].items():
ifm.find('Characteristic')!=-1:
forx,yinn.items():
print"\033[1;34;40m%s\033[0m"%"-"*10
printx,y
else:
print"\033[1;32;40m%s\033[0m"%"-"*10
printm,n
print"\033[1;36;40m%s\033[0m"%"获取服务器内存信息"
forx,yindmidecode.memory().items():
form,niny['data'].items():
print"\033[1;34;40m%s\033[0m"%"-"*10
printm,n
#便于调试,可以删除
print"x"*50
print"\033[1;36;40m%s\033[0m"%"获取服务器主板信息"
forx,yindmidecode.baseboard().items():
#printx,y
form,niny['data'].items():
print"\033[1;34;40m%s\033[0m"%"-"*10
printm,n
print"\033[1;36;40m%s\033[0m"%"获取服务器主板插槽信息"
forx,yindmidecode.slot().items():
form,niny['data'].items():
print"\033[1;34;40m%s\033[0m"%"-"*10
printm,n
print"\033[1;36;40m%s\033[0m"%"获取服务器网卡信息"
"""
安装linux硬件信息收集工具包
"""
#os.system('yum-yinstallmakewgetgcc*;wgethttp://ezix.org/software/files/lshw-B.02.14.tar.gz;tar-zxvflshw-B.02.14
.tar.gz;cdlshw-B.02.14;make&&makeinstall;cd..;rm-rflshw-B.02.14*')
netcard=os.popen('lshw-Cnetwork').read()
print"产品名称:%s"%re.findall('product:.+(?#测试)',netcard)[0]
print"网卡速度:%s"%re.findall('size:.+(?#测试)',netcard)[0]
n=len(re.findall('\*-network:',netcard))
ifn==0:
print"网卡IP地址:%s"%re.findall('ip=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',netcard)[0]
else:
foriinrange(0,n):
try:
print"网卡IP地址:%s"%re.findall('ip=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',netcard)[i]
exceptIndexError:
i+=1
print"第%s块网卡没有IP地址"%i
#print"网卡IP地址:%s"%re.findall('ip=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',netcard)[0]
print"网卡状态:%s"%re.findall('link=\w{3}(?#测试)',netcard)[0]
print"网卡MAC地址:%s"%re.findall('serial:.+(?#测试)',netcard)[0]
print"网卡厂家:%s"%re.findall('vendor:.+(?#测试)',netcard)[0]
print"网络接口名称:%s"%re.findall('logicalname:.+(?#测试)',netcard)[0]
"""
获取系统信息
"""
print"\033[1;36;40m%s\033[0m"%"获取服务器操作系统信息"
importplatform
print"系统cpu位数:%s"%platform.processor()
print"系统信息:%s"%platform.system()
print"操作系统类型:%s"%platform.dist()[0]
print"系统主机名:%s"%platform.node()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。