首页 > 后端开发 > Python教程 > Python获取服务器的厂商和型号信息

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

高洛峰
发布: 2016-10-18 09:39:53
原创
1500 人浏览过

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

脚本内容如下

[root@linuxidc tmp]# cat test.py

1

2

3

4

5

6

7

8

#!/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

1

2

HP

ProLiant DL380p Gen8

登录后复制

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

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

1

dmidecode -t1

登录后复制

输出如下:

[root@linuxidc tmp]# dmidecode -t1

1

2

3

4

5

6

7

8

9

10

11

12

13

# 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]#


本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板