import os import time cmd = ‘ifconfig | grep "RX bytes" | head -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 (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(1) os.system(cmd)
原文:https://www.cnblogs.com/youge-OneSQL/p/11054471.html