歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Python獲取服務器的廠商和型號信息

Python獲取服務器的廠商和型號信息

日期:2017/3/1 9:42:56   编辑:Linux編程

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 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved