Home  >  Article  >  Backend Development  >  Python gets the manufacturer and model information of the server

Python gets the manufacturer and model information of the server

大家讲道理
大家讲道理Original
2016-11-07 17:04:121455browse

Python obtains the manufacturer and model information of the server. Under RHEHL6, the system needs to have the python-dmidecode package pre-installed (it seems to have been installed by default)

The content of the script is as follows

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

When executed, root permission is required. The output is as follows:

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

HP
ProLiant DL380p Gen8


The first line is Manufacturer HP, the second line is the HP server model.

Note: The way to obtain this information through the dmidecode command is:

dmidecode -t1


The output is as follows:

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn