LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1042|回复: 0

新手提问 求解一限速脚本

[复制链接]
发表于 2010-3-24 10:58:21 | 显示全部楼层 |阅读模式
看到一个脚本,想知道这个脚本里面有限制TCP和UDP连接数么,不懂编程,还请大家帮忙,感激不尽
脚本如下
#Copyright by zhoutao0712
echo -e '\n
N=1\n
UPN=40\n
DOWNN=$((N*90))\n
export NET=192.168.1.0/24\n
export UIP="192.168.1."\n
export IPS=125\n
export IPE=130\n

export UP=$((UPN))kbps\n
export DOWN=$((DOWNN))kbps\n
export DOWN2R=$(($DOWNN*35/100))kbps\n
export DOWN2C=$(($DOWNN*80/100))kbps\n
export UP2R=$(($UPN/3))kbps\n
export UP2C=$(($UPN*80/100))kbps\n
ONLINE=$(ip neighbor show |grep -c \n
export UPLOADR=1kbps\n
export UPLOADC=$(($UPN*30/100))kbps\n
export DOWNLOADR=$(($DOWNN*60/100/$((ONLINE+4))))kbps\n
export DOWNLOADC=$(($DOWNN*80/100))kbps\n' >/tmp/regist_env.sh
. /tmp/regist_env.sh

echo 1 >/tmp/online.sh

insmod imq
insmod ipt_IMQ
ifconfig imq1 up
ifconfig imq0 up
iptables -t mangle -I FORWARD -d $NET -o br0 -j IMQ --todev 0
iptables -t mangle -I PREROUTING -s $NET -i br0 -j IMQ --todev 1
iptables -t mangle -I FORWARD -s $NET -d $NET -o br0 -j ACCEPT
iptables -t mangle -I PREROUTING -s $NET -d $NET -i br0 -j ACCEPT

echo -e '\n
tc qdisc del dev imq0 root\n
tc qdisc del dev imq1 root\n' >/tmp/del.sh
echo -e '\n
tc qdisc add dev imq1 root handle 1: htb\n
tc class add dev imq1 parent 1: classid 1:1 htb rate $UP\n
tc qdisc add dev imq0 root handle 1: htb\n
tc class add dev imq0 parent 1: classid 1:1 htb rate $DOWN\n
tc filter add dev imq0 parent 1:0 protocol ip prio 10 u32 match u16 0x0000 0xfc00 at 2 flowid 1:1000\n
tc class add dev imq0 parent 1:1 classid 1:1000 htb rate $DOWN2R ceil $DOWN2C prio 0\n
tc filter add dev imq1 parent 1:0 protocol ip prio 10 u32 match u16 0x0000 0xff80 at 2 flowid 1:1000\n
tc class add dev imq1 parent 1:1 classid 1:1000 htb rate $UP2R ceil $UP2C prio 0\n
i=$IPS;\n
while [ $i -le $IPE ] \n
do\n
tc class add dev imq1 parent 1:1 classid 1:2$i htb rate $UPLOADR ceil $UPLOADC prio 2\n
tc qdisc add dev imq1 parent 1:2$i handle 2$i: sfq perturb 15\n
tc class add dev imq0 parent 1:1 classid 1:1$i htb rate $DOWNLOADR ceil $DOWNLOADC prio 2\n
tc qdisc add dev imq0 parent 1:1$i handle 1$i: sfq perturb 15\n
tc filter add dev imq1 parent 1:0 protocol ip u32 match ip src 192.168.1.$i flowid 1:2$i
tc filter add dev imq0 parent 1:0 protocol ip u32 match ip dst 192.168.1.$i flowid 1:1$i
i=`expr $i + 1`\n
done\n' >/tmp/limit.sh

echo -e '\n
ip neigh flush dev br0\n
sleep 50s\n
ONLINE_OLD=$(cat /tmp/online.sh)\n
ONLINE_NEW=$(ip neighbor show |grep -c \n
SUB_ONLINE=$(($ONLINE_NEW-$ONLINE_OLD))\n
while test $SUB_ONLINE -eq 0\n
do\n
exit\n
done\n
while test $ONLINE_NEW -eq 1\n
do\n
echo $ONLINE_NEW >/tmp/online.sh\n
. /tmp/del.sh\n
exit\n
done\n
while test $ONLINE_OLD -eq 1\n
do\n
echo $ONLINE_NEW >/tmp/online.sh\n
. /tmp/regist_env.sh\n
. /tmp/del.sh\n
. /tmp/limit.sh\n
exit\n
done\n
case $SUB_ONLINE in\n
0)\n
exit;;\n
-1)\n
exit\n
;;\n
1)\n
exit\n
;;\n
*)\n
echo $ONLINE_NEW >/tmp/online.sh\n
. /tmp/regist_env.sh\n
. /tmp/del.sh\n
. /tmp/limit.sh\n
;;\n
esac\n' >/tmp/test_qos.sh
chmod +x /tmp/test_qos.sh
echo ' * * * * * root . /tmp/test_qos.sh' >> /tmp/crontab
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表