当前位置 : 主页 > 操作系统 > centos >

绝对实用LINUX双网卡流量查看脚

来源:互联网 收集:自由互联 发布时间:2022-06-21
原写了个单网卡的,但是具很多朋友及网友反映最好是双网卡流量查看,为了瞒足大家需足,我特意修改脚本了,如功能上还需增加请提出,我尽我所能修改 脚本下载地址:http://down
原写了个单网卡的,但是具很多朋友及网友反映最好是双网卡流量查看,为了瞒足大家需足,我特意修改脚本了,如功能上还需增加请提出,我尽我所能修改
脚本下载地址:http://down.51cto.com/data/279658
运行方法很简单
第一步:设权限[root@skyxue network]# chmod 777 traff.py
第二步:执行脚本[root@skyxue network]# ./traff.py
查看效果图吧绝对实用LINUX双网卡流量查看脚_流量脚本

RX:接收流量TX:发送流量ESTABLISHED:已建立的连接TIME_WAIT:连接等待请求HTTP:80端口连接数
如下是主程序代码#!/usr/bin/python
#Show network of trafficy
#Sky.xue(10.21)
import os,re,time,sys
list_R=[]
list_T=[]
class pattern:
def RX(self):
if len(list_R) < 2:
p=re.compile("RX bytes:\d+")
find=''.join(p.findall(ip))[9:]
list_R.append(find)
if len(list_R) == 2:
count=(int(list_R[1]) - int(list_R[0]))/1024
print eth + '-RX:'+str(count) + "KB/s"

def TX(self):
if len(list_T) < 2:
p=re.compile("TX bytes:\d+")
find=''.join(p.findall(ip))[9:]
list_T.append(find)
if len(list_T) == 2:
count=(int(list_T[1]) - int(list_T[0]))/1024
print eth + '-TX:'+str(count) + "KB/s"

def read(self):
while len(list_R+list_T) < 4:
global ip
ip = os.popen('/sbin/ifconfig %s' % eth ).read()
time.sleep(1)
d.RX()
d.TX()

def network(self):
tcp=os.popen("netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'").read()
http=os.popen("netstat -an |grep '80'|wc -l ").read()
print tcp,'HTTP:'+http

d = pattern()
if __name__ == '__main__':
eth = 'eth0'
print '----------eth0-----------'
d.read()
try:
del list_R[:]
del list_T[:]
eth = 'eth1'
print '----------eth1-----------'
d.read()
finally:
print '----------TCP------------'
d.network()
sys.exit()




上一篇:高性能HTTP加速器Varnish(性能调优篇)
下一篇:没有了
网友评论