2008年(13)
分类: BSD
2008-03-31 16:12:13
#export PKG_PATH=ftp://ftp.freebsdchina.org/pub/OpenBSD/snapshots/packages/i386/
#pkg_add -v pftop-0.5.tgz
#!/bin/sh
$CONFIG_PATH="/root/server"
# ping 一个设定的ip 取其最大的回显值
PING='ping -c 10 10.200.250.11 | awk '{print $7}' | grep ^time | cut -d"=" -f2 | cut -d"." -f1 |
sort | uniq | tail -n 1'
echo $PING
if [ $PING -gt 100 ]
then
# 输出当前所有在线用户并显示其连接数
pftop -ba | sed '1, 5d' | awk '{print $3}' |\
cut -d":" -f1 | grep ^192 | sort | uniq -c | sort > $CONFIG_PATH/log/conn_num.log
pftop -ba | sed '1, 5d' | awk '{print $3}' |\
cut -d":" -f1 | grep ^10 | sort | uniq -c | sort > $CONFIG_PATH/log/conn_server.log
# 提取连接数最多的前十名
tail -n 10 $CONFIG_PATH/log/conn_num.log | grep ^192 | awk '{print $2}' >
$CONFIG_PATH/log/conn_more.log
#抓取当前流量大于m 的ip
pftop -ab | awk '/M$/' | awk '{print $3}' | cut -d":" -f1 | grep ^192 |sort | uniq >
$CONFIG_PATH/log/conn_traff.log
# 提取既流量大连接数也大的ip
for NEW_IP in $(cat $CONFIG_PATH/log/conn_traff.log)
do
for OLD_IP in $(cat $CONFIG_PATH/log/conn_num.log)
do
if [ "X${NEW_IP}" != "X${OLD_IP}" ]
then
echo $TWO_IP >> $CONFIG_PATH/log/conn_two.log
fi
done
done
# 断开流量大的ip
for KILL in $(cat $CONFIG_PATH/log/conn_two.log)
do
pfctl -k $KILL
done
# 清空 nat rules=filter tables queue
pfctl -F nat
pfctl -F rules
pfctl -F Tables
pfctl -F queue
pfctl -f $CONFIG_PATH/pf2.conf
fi
#!/bin/sh
$CONFIG_PATH="/root/server"
# ping 一个设定的ip 取其最大的回显值
PING='ping -c 10 10.200.250.11 | awk '{print $7}' | grep ^time | cut -d"=" -f2 | cut -d"." -f1 |
sort | uniq | tail -n 1'
echo $PING
if [ $PING -gt 100 ]
then
# 输出当前所有在线用户并显示其连接数
pftop -ba | sed '1, 5d' | awk '{print $3}' |\
cut -d":" -f1 | grep ^192 | sort | uniq -c | sort > $CONFIG_PATH/log/conn_num.log
pftop -ba | sed '1, 5d' | awk '{print $3}' |\
cut -d":" -f1 | grep ^10 | sort | uniq -c | sort > $CONFIG_PATH/log/conn_server.log
# 提取连接数最多的前十名
tail -n 10 $CONFIG_PATH/log/conn_num.log | grep ^192 | awk '{print $2}' >
$CONFIG_PATH/log/conn_more.log
#抓取当前流量大于m 的ip
pftop -ab | awk '/M$/' | awk '{print $3}' | cut -d":" -f1 | grep ^192 |sort | uniq >
$CONFIG_PATH/log/conn_traff.log
# 提取既流量大连接数也大的ip
for NEW_IP in $(cat $CONFIG_PATH/log/conn_traff.log)
do
for OLD_IP in $(cat $CONFIG_PATH/log/conn_num.log)
do
if [ "X${NEW_IP}" != "X${OLD_IP}" ]
then
echo $TWO_IP >> $CONFIG_PATH/log/conn_two.log
fi
done
done
# 断开流量大的ip
for KILL in $(cat $CONFIG_PATH/log/conn_two.log)
do
pfctl -k $KILL
done
# 清空 nat rules=filter tables queue
pfctl -F nat
pfctl -F rules
pfctl -F Tables
pfctl -F queue
pfctl -f $CONFIG_PATH/pf2.conf
else
rm -rf $CONFIG_PATH/log/conn_two.log >/dev/null 2>&1
pfctl -F nat
pfctl -F rules
pfctl -F Tables
pfctl -f $CONFIG_PATH/pf.conf
fi
#ftp stream tcp nowait root /usr/libexec/ftpd ftpd -US
#ftp stream tcp6 nowait root /usr/libexec/ftpd ftpd -US
127.0.0.1:8021 stream tcp nowait root /usr/libexec/ftp-proxy ftp-proxy -n -t 180
#!/bin/sh
while :
do
date
sleep 600
/root/server/run-10
done
#!/bin/sh
while :
do
date
sleep 7200
/root/server/run-120
done