亚洲国产精品人久久,亚洲va国产日韩欧美精品色婷婷,久久久久88色偷偷,免费人成黄页在线观看国际

17站長網

17站長網 首頁 腳本 linux shell 查看內容

linux監(jiān)控網絡流量的腳本

2022-12-8 15:41| 查看: 2228 |來源: 互聯(lián)網

我看了下,linux下的/proc/net/dev記錄了每塊網卡發(fā)送和接受的包和字節(jié)數(shù)。因此萌生想法,寫了一個。運行效果: [root@74-82-173-217 ~]# ./net.sh Current Ip: inet addr:74.82.173.217 Bcast:74.82.173.223 Mask:2
我看了下,linux下的/proc/net/dev記錄了每塊網卡發(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

具體腳本的內容如下,幾乎不需要修改,就可以拿到任何機器上去使用了。

[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
本文最后更新于 2022-12-8 15:41,某些文章具有時效性,若有錯誤或已失效,請在網站留言或聯(lián)系站長:17tui@17tui.com
·END·
站長網微信號:w17tui,關注站長、創(chuàng)業(yè)、關注互聯(lián)網人 - 互聯(lián)網創(chuàng)業(yè)者營銷服務中心

免責聲明:本站部分文章和圖片均來自用戶投稿和網絡收集,旨在傳播知識,文章和圖片版權歸原作者及原出處所有,僅供學習與參考,請勿用于商業(yè)用途,如果損害了您的權利,請聯(lián)系我們及時修正或刪除。謝謝!

17站長網微信二維碼

始終以前瞻性的眼光聚焦站長、創(chuàng)業(yè)、互聯(lián)網等領域,為您提供最新最全的互聯(lián)網資訊,幫助站長轉型升級,為互聯(lián)網創(chuàng)業(yè)者提供更加優(yōu)質的創(chuàng)業(yè)信息和品牌營銷服務,與站長一起進步!讓互聯(lián)網創(chuàng)業(yè)者不再孤獨!

掃一掃,關注站長網微信

大家都在看

    熱門排行

      最近更新

        返回頂部