亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

python 獲取linux本機信息【十全十美】

標簽:
Python


   用python写的获取linux本机信息,包括kernel、IP、Memory、Disk信息。

 

################################################################################

#Information on this program is used to get the Linux native.                  #

#You can enter the "kernel", "ip", "memory", "disk" keyword to get the results,# 

#you can also enter "all".                                                     #

###############################################################################

翻译:本程序是用来获取linux本机信息的

      你可以输入“kernel”,“ip”,“memory”,“disk”关键字获取响应的参数信息

      也可以输入“all”,查看所有参数。

程序内容如下:

#!/usr/bin/env python 

#-*- coding:utf-8 -*- 

#2012/12/12 by SongShouJiong 

#Email:[email protected] 

 

import os 

kernel_version = os.popen('''/bin/uname -a | awk \'{print $1,$3}\'''').read().strip('\n') 

ip = os.popen('''/sbin/ifconfig | grep 'inet addr'|awk '{print $2}'|head -1 |cut -d ":" -f 2''').read().strip('\n') 

memory = os.popen('''free -m | head -2''').read().strip('\n') 

disk = os.popen('''df -hT''').read().strip('\n') 

 

print ''' 

################################################################################ 

#Information on this program is used to get the Linux native.                  # 

#You can enter the "kernel", "IP", "memory", "disk" keyword to get the results,#  

#you can also enter "all".                                                     # 

###############################################################################'''.strip('\n') 

 

a = str(raw_input('Please input to query parameter:')) 

if   a == 'kernel': 

    print "Kernel Version:",kernel_version 

elif a == 'ip': 

        print "Local IP:",ip 

elif a == 'memory': 

        print "Local Memory:" + ('\n') + memory 

elif a == 'disk': 

        print "Local Disk:" + ('\n') + disk 

elif a == "all": 

        print "Kernel Version:",kernel_version 

        print "Local IP:",ip 

        print "Local Memory:" + ('\n') + memory 

        print "Local Disk:" + ('\n') + disk 

else: 

    print "Didnt't you want to query parameter." 

 最近在学习python,所以就各种找需求去练习,写的也简单,各种堆命令,有什么不对的地方或者好的建议,还请指出。

©著作权归作者所有:来自51CTO博客作者linuxsong的原创作品,如需转载,请注明出处,否则将追究法律责任

linuxlinux系统信息Python|Shell


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消