#!/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 == '
':
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 这些想要的信息,通过把这些信息用字典来收集,再找到相关的数据信息。