原写了个单网卡的,但是具很多朋友及网友反映最好是双网卡流量查看,为了瞒足大家需足,我特意修改脚本了,如功能上还需增加请提出,我尽我所能修改脚本下载地址:http:..."> 原写了个单网卡的,但是具很多朋友及网友反映最好是双网卡流量查看,为了瞒足大家需足,我特意修改脚本了,如功能上还需增加请提出,我尽我所能修改脚本下载地址:http:..." /> 原写了个单网卡的,但是具很多朋友及网友反映最好是双网卡流量查看,为了瞒足大家需足,我特意修改脚本了,如功能上还需增加请提出,我尽我所能修改脚本下载地址:http:..." />
用户登录
用户注册

分享至

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

  • 作者: 你在逗我85667409
  • 来源: 51数据库
  • 2020-09-18
editor-side-new">
原写了个单网卡的,但是具很多朋友及网友反映最好是双网卡流量查看,为了瞒足大家需足,我特意修改脚本了,如功能上还需增加请提出,我尽我所能修改

脚本下载地址:http://down.51cto.com/data/279658

运行方法很简单
第一步:设权限
[root@skyxue network]# chmod 777 traff.py

第二步:执行脚本
[root@skyxue network]# ./traff.py

查看效果图吧


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()




软件
前端设计
程序设计
Java相关