How does python obtain server hardware information? Does python obtain server information?

Source: Internet
Author: User

How does python obtain server hardware information? Does python obtain server information?

The examples in this article share with you the specific code of the Android jiugongge image for your reference. The specific content is as follows:

#! /Usr/bin/env python #-*-coding: UTF-8-*-import rlcompleter, readlinereadline. parse_and_bind ('tab: complete') import dmidecodeimport timeimport osimport resystem = dmidecode. system () print "\ 033 [1; 36; 40 m % s \ 033 [0 m" % "Get server hardware information" for x, y in system. items (): for I in y ['data']. items (): if I [0] = 'product name': print "\ 033 [1; 31; 40 m % s \ 033 [0 m "%"-"* 10 print 'server models: % s' % I [1] print I print" \ 033 [1; 36; 40 m % S \ 033 [0 m "%" Get server CPU information "for x, y in dmidecode. processor (). items (): for m, n in y. items (): if m = 'data': print "\ 033 [1; 31; 40 m % s \ 033 [0 m" % "-" * 10 for x, y in n. items (): print x, yprint "\ 033 [1; 36; 40 m % s \ 033 [0 m" % "Get server BIOS information" for x, y in dmidecode. bios (). items (): for m, n in y ['data']. items (): if m. find ('characteristic ')! =-1: for x, y in n. items (): print "\ 033 [1; 34; 40 m % s \ 033 [0 m" % "-" * 10 print x, y else: print "\ 033 [1; 32; 40 m % s \ 033 [0 m" % "-" * 10 print m, nprint "\ 033 [1; 36; 40 m % s \ 033 [0 m "%" Get server memory information "for x, y in dmidecode. memory (). items (): for m, n in y ['data']. items (): print "\ 033 [1; 34; 40 m % s \ 033 [0 m" % "-" * 10 print m, n # Easy to debug, you can delete print "x" * 50 print "\ 033 [1; 36; 40 m % s \ 033 [0 m" % "to obtain Server Board information" for x, y in dmidecode. baseboard (). items ():# Print x, y for m, n in y ['data']. items (): print "\ 033 [1; 34; 40 m % s \ 033 [0 m" % "-" * 10 print m, nprint "\ 033 [1; 36; 40 m % s \ 033 [0 m "%" Get server motherboard slot information "for x, y in dmidecode. slot (). items (): for m, n in y ['data']. items (): print "\ 033 [1; 34; 40 m % s \ 033 [0 m" % "-" * 10 print m, nprint "\ 033 [1; 36; 40 m % s \ 033 [0 m "%" Get server Nic information "install linux hardware information collection toolkit" "# OS. system ('yum-y install make wget gcc *; wget http://ezix.org/software/files/lshw- B .02.14.tar.gz; tar-zxvf lshw-B.02.14.tar.gz; cd lshw-B.02.14; make & make install; cd ..; rm-rf lshw-B.02.14 * ') netcard = OS. popen ('lshw-C Network '). read () print "Product Name: % s" % re. findall ('product :. + (? # Test) ', netcard) [0] print "Nic speed: % s" % re. findall ('size:. + (? # Test) ', netcard) [0] n = len (re. findall ('\ *-network:', netcard) if n = 0: print "Nic IP Address: % s" % re. findall ('IP = \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3} ', netcard) [0] else: for I in range (0, n): try: print "Nic IP Address: % s" % re. findall ('IP = \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3} ', netcard) [I] couldn t IndexError: I + = 1 print "The % s Nic has no IP Address" % I # print "Nic IP Address: % s "% re. findall ('IP = \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3} ', netcard) [0] print "Nic status: % s" % re. findall ('link = \ w {3 }(? # Test) ', netcard) [0] print "Nic MAC address: % s" % re. findall ('serial:. + (? # Test) ', netcard) [0] print "Nic manufacturer: % s" % re. findall ('vendor:. + (? # Test) ', netcard) [0] print "Network Interface name: % s" % re. findall ('logical name:. + (? # Test) ', netcard) [0] "retrieve system information" print "\ 033 [1; 36; 40 m % s \ 033 [0 m "%" Get Server OS information "import platformprint" system cpu bits: % s "% platform. processor () print "system information: % s" % platform. system () print "operating system type: % s" % platform. dist () [0] print "system Host Name: % s" % platform. node ()

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.