收集主機資訊

來源:互聯網
上載者:User

標籤:收集主機資訊

收集主機資訊,包括:

1、主機名稱:hostname

2、IP地址:ip

3、作業系統版本:osver

4、伺服器廠商:vendor

5、伺服器型號:product

6、伺服器序號:sn

7、cpu型號:cpu_module

8、cpu核心數量:cpu_num

9、記憶體大小


收集IP資訊

[[email protected] systeminformation]# vim sysinformation.pyfrom subprocess import Popen,PIPEdef getIfconfig():    p = Popen([‘ifconfig‘],stdout=PIPE)    data = p.stdout.read()    return datadef getDmi():    p = Popen([‘dmidecode‘],stdout = PIPE)    data = p.stdout.read()    return datadef parseData(data):    parsed_data = []    new_line = ‘‘    data = [i for i in data.split(‘\n‘) if i ]    for line in data:        if line[0].strip():            parsed_data.append(new_line)            new_line = line + ‘\n‘        else:            new_line +=line + ‘\n‘    parsed_data.append(new_line)    return parsed_datadef parseIfconfig(parsed_data):    dic = {}    tuple_addr= (‘lo‘,‘vir‘,‘vnet‘,‘em3‘,‘em4‘)    parsed_data = [i for i in parsed_data if i and not i.startswith(‘tuple_addr‘)]    for lines in parsed_data:        line_list = lines.split(‘\n‘)        devname = line_list[0].split()[0]        macaddr = line_list[0].split()[-1]        ipaddr = line_list[1].split()[1].split(‘:‘)[1]        break    dic [‘ip‘] = [devname, ipaddr, macaddr]    return dicif __name__ == "__main__":    data = getIfconfig()    parsed_data = parseData(data)    print parseIfconfig(parsed_data)[[email protected] systeminformation]# python sysinformation.py{‘ip‘: [‘br1‘, ‘112.65.140.133‘, ‘A4:BA:DB:20:93:23‘]}





本文出自 “梅花香自苦寒來!” 部落格,請務必保留此出處http://daixuan.blog.51cto.com/5426657/1886691

收集主機資訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.