#!/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. Django runserver支持https

    创建自签名ssl证书 1.下载软件openssl-0.9.8k_WIN32 2.解压后进入bin目录,双击打开openssl.exe,依次运行如下命令 genrsa -des3 -out server ...

  2. Linux常见的系統进程

    前言 在日常运维工作中,经常会看到一些奇怪的系统进程占用资源比较高.而且总是会听到业务线同学询问“xxx这个是啥进程啊?咋开启了这么多?” 而这些系统级的内核进程都是会用中括号括起来的,它们会执行一些 ...

  3. GTF/GFF

  4. A1082 Read Number in Chinese (25)(25 分)

    A1082 Read Number in Chinese (25)(25 分) Given an integer with no more than 9 digits, you are suppose ...

  5. 笔记-http-header

    笔记-http-header 1.      Requests部分 Host:请求的web服务器域名地址 User-Agent:HTTP客户端运行的浏览器类型的详细信息.通过该头部信息,web服务器可 ...

  6. python之时间处理time模块

    import time import datetime ''' print(time.time()) #返回当前系统时间戳 print(time.ctime()) #返回当前系统时间 print(ti ...

  7. open()函数之文件操作

    #open() 文件操作 #打开文件的模式有: r,只读模式[默认] w,只写模式[不可读:不存在则创建:存在则清空内容:] x,只写模式[不可读:不存在则创建,存在则报错] a,追加模式[可读:不存 ...

  8. HttpRunnerManager 接口自动化测试平台 搭建实践

    一.需要准备的知识点 1. linux: 安装 python3.nginx 安装和配置.mysql 安装和配置 2. python: django 配置.uwsgi 配置 二.我搭建的环境 1. Ce ...

  9. Tensorflow打造聊天机器人

    Tensorflow聊天机器人 聊天机器人也叫做对话系统,是一个热门领域.微软.facebook.苹果.google.微信.slack都在上面做了大的投入,这是一波新的试图改变人和服务交流的创业浪潮. ...

  10. Your branch is ahead of 'origin/master' by 21 commits.

    当切换到主分支后,准备 git pull 拉取远程 master 分支时,提示本地主分支显示有 21 个commits 问题原因: 因为你修改了 local master 本地的主分支,可以选择以下方 ...