博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python学习:Dmidecode系统信息(一)
阅读量:7010 次
发布时间:2019-06-28

本文共 773 字,大约阅读时间需要 2 分钟。

#!/usr/bin/env python
 
from subprocess import Popen, PIPE
 
p = Popen(['dmidecode'], stdout=PIPE)
data = p.stdout
lines = []
dmi = {}
a = True
while a:
    line = data.readline()
    if line.startswith('System Information'):
        while True:
            line = data.readline()
            if line == '\n':
                a = False
                break
            else:
                lines.append(line)
dmi_dic = dict([i.strip().split(':') for i in lines])
dmi['Manufacturer'] = dmi_dic['Manufacturer'].strip()
dmi['Product'] = dmi_dic['Product Name'].strip()
dmi['Serial'] = dmi_dic['Serial Number'].strip()
print dmi
 
 
[root@web10 day2]# python 11_dmi.py
{'Product': 'VMware Virtual Platform', 'Serial': 'VMware-56 4d 59 f9 29 2e 09 a1-57 0e 95 aa b3 b7 57 8f', 'Manufacturer': 'VMware, Inc.'}
 
收集到关于 product, serial number, manufacture 这些想要的信息,通过把这些信息用字典来收集,再找到相关的数据信息。

转载地址:http://khjtl.baihongyu.com/

你可能感兴趣的文章