dmidecode.py (Python3_dmidecode)

Source: Internet
Author: User

#!/usr/bin/env Python3#-*-coding:utf-8-*-ImportsubprocessImportRedict_sn_productname= {}defGetdmidecode ():#    #variable ' out ' is subprocess output infoTop_info = subprocess. Popen (["Dmidecode","- T","system"], stdout=subprocess. PIPE) out, err=top_info.communicate ()#Output Info Get from console have many Unicode escape character, such as \x1b (B\X1B[M\X1B[39;49M\X1B[K\N\X1B (b\x1b[m
        #Use decode (' Unicode-escape ') to processOut_info = Out.decode ('Unicode-escape')    #print (out_info)Lines =[] Lines= Out_info.split ('\ n')    #return Out_info    #Get serial number    if 'Serial Number' inchOut_info:serialnumbersearch= Re.compile ('Serial Number: (. +?) \ n') SerialNumber=Serialnumbersearch.findall (Out_info) [0] dict_sn_productname['serialnumber'] =serialnumber#Get Product Name    if 'Product Name' inchOut_info:productnamesearch= Re.compile ('Product Name: (. +?) \ n') ProductName=Productnamesearch.findall (Out_info) [0] dict_sn_productname['ProductName'] =Productnamegetdmidecode ()Print(Dict_sn_productname)

Output
[[email protected] mgmtstatus] # ./dmidecode.py {'productName':'IBM System x3650 M4:-[7915r7q]-',' serialnumber ':'06BAFCD'}[[email protected] mgmtstatus]#



From for notes (Wiz)



dmidecode.py (Python3_dmidecode)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.