python如何获取服务器硬件信息

作者:zhangjpn 时间:2023-05-10 18:28:06 

本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下


#!/usr/bin/env python
# -*- coding: utf-8 -*-
import rlcompleter, readline
readline.parse_and_bind('tab: complete')
import dmidecode
import  time
import  os
import  re
system=dmidecode.system()
print "\033[1;36;40m%s\033[0m" %"获取服务器硬件信息"
for x,y in system.items():
for i in y['data'].items():
if i[0] == 'Product Name':
print "\033[1;31;40m%s\033[0m" % "-"*10
print 'Server models: %s' %i[1]  
print i

print "\033[1;36;40m%s\033[0m" % "获取服务器CPU信息"
for x,y in dmidecode.processor().items():
 for m,n in y.items():
 if m=='data':
print "\033[1;31;40m%s\033[0m" % "-"*10
 for x,y in n.items():
   print x,y
print "\033[1;36;40m%s\033[0m" %"获取服务器BIOS信息"
for x,y in dmidecode.bios().items():
for m,n in y['data'].items():
 if m.find('Characteristic')!=-1:
   for x,y in n.items():
   print "\033[1;34;40m%s\033[0m" % "-"*10
   print x,y
 else:
   print "\033[1;32;40m%s\033[0m" % "-"*10
   print m,n
print "\033[1;36;40m%s\033[0m" %"获取服务器内存信息"
for x,y in dmidecode.memory().items():
 for m,n in y['data'].items():
   print "\033[1;34;40m%s\033[0m" % "-"*10
   print m,n
#便于调试,可以删除
print "x"*50
print "\033[1;36;40m%s\033[0m" %"获取服务器主板信息"
for x,y in dmidecode.baseboard().items():
 #print x,y
 for m,n in y['data'].items():
   print "\033[1;34;40m%s\033[0m" % "-"*10
   print m,n
print "\033[1;36;40m%s\033[0m" %"获取服务器主板插槽信息"
for x,y in dmidecode.slot().items():
 for m,n in y['data'].items():
   print "\033[1;34;40m%s\033[0m" % "-"*10
   print m,n
print "\033[1;36;40m%s\033[0m" %"获取服务器网卡信息"
"""
安装linux硬件信息收集工具包
 """
#os.system('yum -y install make wget gcc* ;wget http://ezix.org/software/files/lshw-B.02.14.tar.gz ; tar -zxvf lshw-B.02.14
.tar.gz ;cd lshw-B.02.14 ; make && make install ; cd .. ; rm -rf lshw-B.02.14* ')
netcard=os.popen('lshw -C network  ').read( )
print "产品名称: %s"     % re.findall('product:.+(?#测试)',netcard)[0]
print "网卡速度: %s"     % re.findall('size:.+(?#测试)',netcard)[0]
n=len(re.findall('\*-network:',netcard))
if n==0:
 print "网卡IP地址: %s"     %re.findall('ip=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',netcard)[0]
else:
 for i in range(0,n):
    try:
     print "网卡IP地址: %s" %re.findall('ip=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',netcard)[i]
   except IndexError:
     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('logical name:.+(?#测试)',netcard)[0]
"""
获取系统信息
"""
print "\033[1;36;40m%s\033[0m" %"获取服务器操作系统信息"
import platform
print "系统cpu位数: %s " % platform.processor()
print "系统信息: %s "   % platform.system()
print "操作系统类型: %s" % platform.dist()[0]
print "系统主机名: %s "  % platform.node()
标签:python,服务器
0
投稿

猜你喜欢

  • MySQL Shell的介绍以及安装

    2024-01-28 20:03:18
  • Python中一般处理中文的几种方法

    2023-10-11 01:45:23
  • Python中的jquery PyQuery库使用小结

    2023-05-27 11:08:15
  • vue实现右键弹出菜单

    2024-05-21 10:17:41
  • 修改新云CMS底部版权信息字数限制

    2008-07-31 18:00:00
  • 浅谈Golang的方法传递值应该注意的地方

    2024-02-12 07:40:20
  • Python中将字典转换为XML以及相关的命名空间解析

    2022-07-22 20:05:03
  • javascript引导程序

    2024-04-16 10:31:16
  • Js通过AES加密后PHP用Openssl解密的方法

    2023-07-17 08:04:42
  • Python用requests库爬取返回为空的解决办法

    2021-10-30 04:54:29
  • python cv2截取不规则区域图片实例

    2022-08-31 18:58:42
  • 用Python抢火车票的简单小程序实现解析

    2023-09-06 06:31:28
  • Pandas数据分析固定时间点和时间差

    2022-03-05 20:24:07
  • Python使用Nocalhost并开启debug调试的方法

    2023-05-04 11:22:46
  • python爬虫 urllib模块url编码处理详解

    2021-09-13 02:24:37
  • mysql日志滚动

    2024-01-26 18:38:52
  • Python3爬虫之urllib携带cookie爬取网页的方法

    2022-07-01 14:19:02
  • 最强Python可视化绘图库Plotly详解用法

    2022-03-08 11:01:07
  • 用户体验的时间尺度[译]

    2009-10-30 18:25:00
  • vue实现动态路由详细

    2024-05-05 09:25:19
  • asp之家 网络编程 m.aspxhome.com