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)
linux查看每秒的网络流量python版
最新推荐文章于 2024-10-12 21:06:55 发布