主頁 > 知識庫 > linux下監(jiān)控網(wǎng)絡流量的腳本

linux下監(jiān)控網(wǎng)絡流量的腳本

熱門標簽:鐵路電話系統(tǒng) 呼叫中心市場需求 AI電銷 網(wǎng)站排名優(yōu)化 服務外包 Linux服務器 百度競價排名 地方門戶網(wǎng)站
我看了下,linux下的/proc/net/dev記錄了每塊網(wǎng)卡發(fā)送和接受的包和字節(jié)數(shù)。因此萌生想法,寫了一個。運行效果:

復制代碼 代碼如下:

[root@74-82-173-217 ~]# ./net.sh
Current Ip: inet addr:74.82.173.217 Bcast:74.82.173.223 Mask:255.255.255.224
Summry info: RX bytes:203692709 (194.2 MiB) TX bytes:93525930 (89.1 MiB)
eth0 Receive Bytes: 573 Packets: 3
eth0 Send Bytes: 3086 Packets: 3
eth0 Receive Bytes: 378 Packets: 7
eth0 Send Bytes: 11236 Packets: 7
eth0 Receive Bytes: 324 Packets: 6
eth0 Send Bytes: 444 Packets: 2
eth0 Receive Bytes: 54 Packets: 1
eth0 Send Bytes: 0 Packets: 0


具體腳本的內(nèi)容如下,幾乎不需要修改,就可以拿到任何機器上去使用了。
復制代碼 代碼如下:

[root@74-82-173-217 ~]# cat net.sh
#! /bin/bash
#Author: Vogts WangTao 2008-12-18
#Get summry info
echo "Current Ip: "`/sbin/ifconfig eth0 | grep inet`
echo "Summry info: "`/sbin/ifconfig eth0 | grep bytes`
#sleep 1 second ,monitor eth0
while true
do
receive1=`cat /proc/net/dev|grep eth0 | awk '{print$1}'|sed -s 's/eth0://g'`
receive_pack1=`cat /proc/net/dev|grep eth0 | awk '{print$2}'`
send1=`cat /proc/net/dev|grep eth0 | awk '{print$9}'`
send_pack1=`cat /proc/net/dev|grep eth0 | awk '{print$10}'`
sleep 1
receive2=`cat /proc/net/dev|grep eth0 | awk '{print$1}'|sed -s 's/eth0://g'`
receive_pack2=`cat /proc/net/dev|grep eth0 | awk '{print$2}'`
receive_cnt=`expr $receive2 - $receive1`
receive_pack_cnt=`expr $receive_pack2 - $receive_pack1`
send2=`cat /proc/net/dev|grep eth0 | awk '{print$9}'`
send_pack2=`cat /proc/net/dev|grep eth0 | awk '{print$10}'`
send_cnt=`expr $send2 - $send1`
send_pack_cnt=`expr $send_pack2 - $send_pack1`
echo 'eth0 Receive Bytes:' $receive_cnt ' Packets:' $receive_pack_cnt
echo 'eth0 Send Bytes:' $send_cnt ' Packets:' $send_pack_cnt
done
您可能感興趣的文章:
  • linux 雙網(wǎng)卡綁定網(wǎng)絡設置方法
  • Linux網(wǎng)絡編程之基于UDP實現(xiàn)可靠的文件傳輸示例
  • Linux下用netstat查看網(wǎng)絡狀態(tài)、端口狀態(tài)
  • linux命令學習之10個網(wǎng)絡命令和監(jiān)控命令
  • 檢查linux網(wǎng)絡狀態(tài)的兩個腳本
  • Linux基本網(wǎng)絡配置方法介紹
  • Linux 檢測服務器是否連接著網(wǎng)絡
  • Linux的常用網(wǎng)絡命令
  • Linux下的網(wǎng)絡監(jiān)聽技術之一
  • Linux模擬網(wǎng)絡丟包與延遲的方法

標簽:湖南 仙桃 銅川 衡水 崇左 黃山 湘潭 蘭州

巨人網(wǎng)絡通訊聲明:本文標題《linux下監(jiān)控網(wǎng)絡流量的腳本》,本文關鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266