linux下监控网络流量的脚本
时间:2023-08-06 06:40:26
我看了下,linux下的/proc/net/dev记录了每块网卡发送和接受的包和字节数。因此萌生想法,写了一个。运行效果:
[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
标签:监控网络流量


猜你喜欢
Godaddy的VPS服务器怎么重启
2010-04-17 13:13:00
SMTP服务扩展
2010-03-16 18:48:00
新站如何合理与其他网站做友情链接
2007-10-11 17:52:00
linux服务器CPU飙高排查分析
2023-10-12 17:40:44

升级为Exchange 2007后怀念的10件事
2010-02-22 19:16:00
关于搜索引擎优化的五十个一句话实用技巧
2008-12-10 13:32:00
留下一个好影响:网站首页应该放什么内容
2009-01-04 09:31:00
中国地区Yahoo信箱升级为279G
2008-07-29 13:03:00

Linux系统 为命令配置别名的方法
2023-10-13 00:20:15
Eclipse启动Tomcat后无法访问项目解决办法
2022-06-22 02:00:15

评价网站服务器软件的几个方面
2007-09-03 14:02:00
百度K站及关键字等问题看法和疑问
2007-11-20 13:16:00
老谢:企业如何找到自己的新闻点来做推广
2009-04-07 05:14:00
2011年2月Godaddy最新优惠码(含30%折扣优惠码)
2011-01-29 16:54:00
在Windows系统下搭建SVN服务器
2009-08-30 08:00:00

WordPress评论表情启用以及自定义表情
2011-09-07 17:13:54
Apache 本地服务器启动后又自动停止解决办法
2023-11-03 07:19:49
如何保证文件传输服务器FTP的安全
2007-03-26 15:54:00
Windows 2003上网配置DNS的技巧
2008-02-22 10:23:00
百度被伊朗黑客攻陷
2010-01-12 13:42:00
