国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Linux > 正文

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

2019-10-26 18:32:08
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
我看了下,linux下的/proc/net/dev記錄了每塊網(wǎng)卡發(fā)送和接受的包和字節(jié)數(shù)。因此萌生想法,寫(xiě)了一個(gè)。運(yùn)行效果:

代碼如下:
[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)容如下,幾乎不需要修改,就可以拿到任何機(jī)器上去使用了。
代碼如下:
[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
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 南木林县| 旅游| 佳木斯市| 汪清县| 延寿县| 收藏| 高州市| 福建省| 潞西市| 澜沧| 义马市| 长寿区| 苍山县| 安泽县| 乌拉特中旗| 台山市| 长兴县| 富裕县| 同仁县| 江西省| 大同市| 叙永县| 东海县| 株洲县| 长武县| 汉寿县| 合山市| 筠连县| 泸定县| 万盛区| 班戈县| 鹤山市| 泰安市| 九江市| 通道| 天等县| 禄丰县| 秦皇岛市| 丹江口市| 屯昌县| 茌平县|