#!/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获取服务器硬件信息[转]的更多相关文章

  1. (部署新java程序,程序报错,需copy的一个包)——java使用siger 获取服务器硬件信息

    mcat-siger.sh  查看是否安装siger rsync -aPuv /usr/lib64/libsigar-amd64-linux.so $i:/usr/lib64/ java使用siger ...

  2. 通过python脚本获取服务器硬件信息

    #!/usr/bin/python # coding:utf-8 """ 采集机器自身信息 1 主机名 2 内存 3 ip与mac地址 4 cpu信息 5 硬盘分区信息 ...

  3. python 获取对象信息

    当我们拿到一个对象的引用时,如何知道这个对象是什么类型.有哪些方法呢? 使用type() 首先,我们来判断对象类型,使用type()函数: 基本类型都可以用type()判断: >>> ...

  4. Python 获取车票信息

    提示:该代码仅供学习使用,切勿滥用!!! 先来一个git地址:https://gitee.com/wang_li/li_wang 效果图: 逻辑: 1.获取Json文件的内容 2.根据信息生成URL ...

  5. 用python获取ip信息

    1.138网站 http://user.ip138.com/ip/首次注册后赠送1000次请求,API接口请求格式如下,必须要有token值 import httplib2 from urllib.p ...

  6. python获取对象信息

    获取对象信息 拿到一个变量,除了用 isinstance() 判断它是否是某种类型的实例外,还有没有别的方法获取到更多的信息呢? 例如,已有定义: class Person(object): def ...

  7. python获取机器信息脚本(网上寻找的)

    获取机器信息(待测试) # -*- coding: UTF-8 -*- import psutil import json import os import socket import struct ...

  8. python获取的信息列表微信公共平台和用户头像

    转载注明原文地址:http://blog.csdn.net/btyh17mxy/article/details/25207889 只写模拟登陆的方式获取微信从信息和头像库列表公共平台, - 相关后,功 ...

  9. 关于Python 获取windows信息收集

    收集一些Python操作windows的代码 (不管是自带的or第三方库)均来自网上 1.shutdown 操作 定时关机.重启.注销 #!/usr/bin/python #-*-coding:utf ...

随机推荐

  1. MySQL 如何生成日期表

    MySQL 如何生成日期表 在开发过程中,经常会遇到统计问题,通常交易信息都不是连续的,此时,统计出来的数据都是不连续的,所以提前生成一个时期表,当没有交易数据的时候填充0,就可以了,下面是生成日期表 ...

  2. java中常用的swing组件 (2013-10-27-163 写的日志迁移

    五种布局:   流式布局(FlowLayout)边界布局(borderLayout)网格布局(GridLayout)  盒子布局(BoxLaYout)  空布局(null)  常用的几种 卡片布局(C ...

  3. wampserver怎么设置外网可访问

    wampserver配置httpd.conf允许外网访问? 在电脑上开启wamp服务后,默认是禁止外部网络访问的,如果您想要同一局域网中的设备能够访问PC上的web项目,则需要对httpd.conf文 ...

  4. Ubuntu samba 安装与配置 实现windows和虚拟机中的Ubuntu共享文件

    2.    安装sumba服务 sudo apt-get install samba samba-common 这里出现了小问题, Ubuntu上安装samba不能安装的问题,“下列的软件包有不能满足 ...

  5. #2 create and populate a database && realistic and practical applications (PART 2)

    Extends from the last chapter , This chapter takes a look at some real-world problems that can occur ...

  6. 【Word Ladder II】cpp

    题目: Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) ...

  7. 【Remove Duplicates from Sorted List II 】cpp

    题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct  ...

  8. C# 引用访问权限

    同样代码表现的不同行为 创建基类(Super)和派生类(Sub)每个类有一个字段field和一个公共方法getField,并且使用内联的方式初始化为1,方法getField返回字段field.C#和J ...

  9. Mac OS X 上的Apache配置

    Mac系统自带apache服务器 查看apache版本 sudo apachectl -v 启动apache sudo apachectl start 重启apache sudo apachectl ...

  10. poj3748 位运算 bitset

    位操作 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9064   Accepted: 3626 Description 假 ...