歡迎您光臨本站 註冊首頁

絕對實用LINUX雙網卡流量查看腳

←手機掃碼閱讀     火星人 @ 2014-03-08 , reply:0
原寫了個單網卡的,但是具很多朋友及網友反映最好是雙網卡流量查看,為了瞞足大家需足,我特意修改腳本了,如功能上還需增加請提出,我盡我所能修改
腳本下載地址: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()




本文出自 「Newbie's World」 博客,請務必保留此出處http://skyson.blog.51cto.com/2497647/704276


[火星人 ] 絕對實用LINUX雙網卡流量查看腳已經有773次圍觀

http://coctec.com/docs/linux/show-post-46528.html