python监控网卡流量,python监控网卡,[Python]代码im
python监控网卡流量,python监控网卡,[Python]代码im
[Python]代码
import re,timedef get_net_info(): flow1 = open('/proc/net/dev') lines = flow1.read() flow1.close() e = re.compile('(eth.)') r_re = re.compile('eth..(.*?\s)') r_tr = re.compile(".*eth.*") match_re = r_re.findall(lines) match_tr = r_tr.findall(lines) eth = e.findall(lines) return (eth,lines,match_re,match_tr)def net_flow(): net_re_c={} net_tr_c={} net_tr_a=[] for i in get_net_info()[3]: net_tr_a.append(i.split()[8]) net_tr_a=dict(zip(get_net_info()[0],net_tr_a)) net_re_a = dict(zip(get_net_info()[0],get_net_info()[2])) print "{eth0:(transmit,receive)" while True: time.sleep(1) net_re_b = dict(zip(get_net_info()[0],get_net_info()[2])) net_tr_b = [] for i in get_net_info()[3]: net_tr_b.append(i.split()[8]) net_tr_b=dict(zip(get_net_info()[0],net_tr_b)) for i in net_re_b: net_re_c[i] = int((float(net_re_b[i])-float(net_re_a[i]))/1024) for i in net_tr_b: net_tr_c[i]=int((float(net_tr_b[i])-float(net_tr_a[i]))/1024) net_re_a = net_re_b net_tr_a = net_tr_b net_flow={} for a in net_re_c: net_flow[a]=(net_tr_c[a],net_re_c[a]) print net_flow if __name__ == "__main__": net_flow()
相关内容
- Find the coefficients of the polynomial that fits the specified data
- tinyipdate最新ip库 python操作类,tinyipdatepython,发布最新版
- Linux下歌词编辑器,Linux歌词编辑器,#!/usr/bin/e
- 支持编辑的词典,编辑词典,DictForGeeks
- Python倒计时代码,python倒计时,#!/usr/bin/e
- 教师统计学生交作业次数,教师统计作业次数,[Python]代
- select 实现的 socket服务器,selectsocket,[Python]代码im
- python编码,,[Python]代码#
- Tornado 实现实时消息聊天,tornado实时,关键代码之 Mess
- 比较两个文件夹中的代码变化,两个文件夹代码变化
评论关闭