Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  shell  >  正文 iptables统计流量的shell脚本

iptables统计流量的shell脚本

发布时间:2014-11-26   编辑:www.jquerycn.cn
本文分享一段shell脚本,借助iptables实现流量的统计,有需要的朋友参考下。

使用iptables统计流量的一段shell脚本。
代码:
 

复制代码 代码示例:

#!/bin/sh
##
## $Id$ #

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
export PATH

TMP_DIR=/tmp
TMP_FILE=all_bytes_iptables
TMP_SQL=all_sql_file_iptables

IPTABLES=iptables
IPTABLES_OPTIONS="-L ${1} -n -x -v "
GREP=grep
SED=sed
TR=tr
CAT=cat
CUT=cut

cd ${TMP_DIR}
${IPTABLES} ${IPTABLES_OPTIONS} | ${TR} -s ' ' | ${SED} -e 's/^ //' \
| ${GREP} "^[0-9]" | ${CUT} -d' ' -f2,8,9 > ${TMP_FILE}

#
# Bytes for output
#
echo "Start for OUTPUT"
${CAT} ${TMP_FILE} | ${CUT} -d' ' -f1,2 | ${GREP} -v "0.0.0.0/0"

#
# Bytes for input
#
echo "Start for INPUT"
${CAT} ${TMP_FILE} | ${CUT} -d' ' -f1,3 | ${GREP} -v "0.0.0.0/0"

您可能感兴趣的文章:
iptables统计流量的shell脚本
用于管理iptables的shell脚本一例
二个iptables shell脚本(经典收藏)
我的iptables配置脚本实例
结合iptables防止ssh暴力破解的shell
计算网卡流量的shell脚本(代码分享)
在shell中判断iptables是否开启的方法
管理iptables的shell脚本一例
linux iptables入门教程
封锁恶意IP地址的iptables脚本

[关闭]