手机版
你好,游客 登录 注册
背景:
阅读新闻

Python获取服务器的厂商和型号信息

[日期:2014-06-18] 来源:Linux社区  作者:xiaosu [字体: ]

Python获取服务器的厂商和型号信息,在RHEHL6下,需要系统预装python-dmidecode这个包(貌似默认就已经装过了)

脚本内容如下

[root@linuxidc tmp]# cat test.py

#!/usr/bin/env python


import dmidecode

info=dmidecode.system()

info_keys=info.keys()

for i in range(len(info_keys)):

    if info[info_keys[i]]['dmi_type'] == 1 :

        print info[info_keys[i]]['data']['Manufacturer']

        print info[info_keys[i]]['data']['Product Name']

 


[root@linuxidc tmp]#

执行的时候,需要root权限,输出如下:

[root@linuxidc tmp]# ./test.py

HP

ProLiant DL380p Gen8

第一行是厂商HP,第二行是HP服务器的型号。

 


注:通过dmidecode命令获取这些信息的方式是:

dmidecode -t1

输出如下:

[root@linuxidc tmp]# dmidecode -t1

# dmidecode 2.11

SMBIOS 2.7 present.

 


Handle 0x0100, DMI type 1, 27 bytes

System Information

        Manufacturer: HP

        Product Name: ProLiant DL380p Gen8

        Version: Not Specified

        Serial Number: CNG230SHDQ

        UUID: 32333536-3030-4E43-4732-333053484451

        Wake-up Type: Power Switch

        SKU Number: 653200-B21

        Family: ProLiant

[root@linuxidc tmp]#

《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版] http://www.linuxidc.com/Linux/2013-06/85425.htm

《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码] http://www.linuxidc.com/Linux/2013-11/92693.htm

Python脚本获取Linux系统信息 http://www.linuxidc.com/Linux/2013-08/88531.htm

Ubuntu下用Python搭建桌面算法交易研究环境 http://www.linuxidc.com/Linux/2013-11/92534.htm

Python 的详细介绍请点这里
Python 的下载地址请点这里

本文永久更新链接地址http://www.linuxidc.com/Linux/2014-06/103369.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款