1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| [iyunv@133 systeminformation]# vim dmidecode_1.py
#!/usr/bin/env python
from subprocess import Popen,PIPE
p = Popen(['dmidecode'],stdout=PIPE)
data=p.stdout
line_s = [] #定义一个空列表
dmi = {} #定义一个空字典
a = True #设置标志位 a = True
while a:
line = data.readline()
if line.startswith('System Information'): #判断以System Information开头的段,
while True:
line = data.readline()
if line == '\n': #取该段落,直到有空行
a = False
break
else:
line_s.append(line)
dmi_dic = dict([i.strip().split(':') for i in line_s]) #把空格和换行符删除
dmi['Manufacturer'] = dmi_dic['Manufacturer'].strip() #打印key= Manufacturer的键值对
print dmi
print {'\n'*20}
for k,v in dmi_dic.items(): #打印以System Information开头的段,以key、value打印出来
dmi[k] = v.strip()
print dmi
[iyunv@133 systeminformation]# python dmidecode_1.py
{'Manufacturer': 'Dell Inc.'}
set(['\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'])
{'SKU Number': 'Not Specified', 'UUID': '4C4C4544-0048-4210-8044-B4C04F543258', 'Family': 'Not Specified', 'Serial Number': '4HBDT2X', 'Version': 'Not Specified', 'Product Name':
'PowerEdge R710', 'Wake-up Type': 'Power Switch', 'Manufacturer': 'Dell Inc.'}
|