linux查看每秒的网络流量


import os
import time
cmd = 'ifconfig | grep "RX bytes" | tail -1 | awk -F":" \'{print $2," ", $3}\' | awk \'{print $1 , " " , $6}\' > network_speed.temp'
os.system(cmd)
tx=0
rx=0
while True:
        file = open('network_speed.temp')
        for line in file:
                fields = line.strip().split()
        print time.asctime( time.localtime(time.time()) ), " " ,(int(fields[0]) - tx)/1024.0/1024.0, " ", (int(fields[1]) - rx)/1024.0/1024.0
        tx = int(fields[0])
        rx= int(fields[1])
        time.sleep(0.1)
        os.system(cmd)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM