|
发表于 2008-8-13 14:43:18
|
显示全部楼层
呵呵,前段时间帮别人做了个4线均衡,完整考虑到了其中某一线或某几线断开时的调整,以下是检测调整的脚本
:global ip
:global gateold
:global address
:global ii 0
/interface pppoe-client monitor pppoe-out1 once do={:global adsl-statu $status}
:if ($adsl-statu="connected") do={
:set ip [/ip add get [/ip add find inter=pppoe-out1 dynamic=yes] address]
:set address [:pick $ip 0 [:find $ip "/"]]
:set gateold [/ip route get [/ip route find comm=adsl1] gateway]
:if ($gateold!=$address) do={
/ip add set [/ip add find comm=adsl1] address=$ip network=$address broadcast=$address
/ip route set [/ip route find comm=adsl1] gateway=$address
}
:set ii ($ii+1)
}
/interface pppoe-client monitor pppoe-out2 once do={:global adsl-statu $status}
:if ($adsl-statu="connected") do={
:set ip [/ip add get [/ip add find inter=pppoe-out2 dynamic=yes] address]
:set address [:pick $ip 0 [:find $ip "/"]]
:set gateold [/ip route get [/ip route find comm=adsl2] gateway]
:if ($gateold!=$address) do={
/ip add set [/ip add find comm=adsl2] address=$ip network=$address broadcast=$address
/ip route set [/ip route find comm=adsl2] gateway=$address
}
:set ii ($ii+1)
}
/interface pppoe-client monitor pppoe-out3 once do={:global adsl-statu $status}
:if ($adsl-statu="connected") do={
:set ip [/ip add get [/ip add find inter=pppoe-out3 dynamic=yes] address]
:set address [:pick $ip 0 [:find $ip "/"]]
:set gateold [/ip route get [/ip route find comm=adsl3] gateway]
:if ($gateold!=$address) do={
/ip add set [/ip add find comm=adsl3] address=$ip network=$address broadcast=$address
/ip route set [/ip route find comm=adsl3] gateway=$address
}
:set ii ($ii+1)
}
/interface pppoe-client monitor pppoe-out4 once do={:global adsl-statu $status}
:if ($adsl-statu="connected") do={
:set ip [/ip add get [/ip add find inter=pppoe-out4 dynamic=yes] address]
:set address [:pick $ip 0 [:find $ip "/"]]
:set gateold [/ip route get [/ip route find comm=adsl4] gateway]
:if ($gateold!=$address) do={
/ip add set [/ip add find comm=adsl4] address=$ip network=$address broadcast=$address
/ip route set [/ip route find comm=adsl4] gateway=$address
}
:set ii ($ii+1)
}
:if ($ii=2) do={
:if ([ip fi man get [/ip fi man find comm=adsl1] disabled]=yes) do={/ip fi man en [/ip fi man find comm=adsl1]}
:if ([ip fi man get [/ip fi man find comm=adsl2] disabled]=yes) do={/ip fi man en [/ip fi man find comm=adsl2]}
:if ([ip fi man get [/ip fi man find comm=adsl3] disabled]=no) do={/ip fi man dis [/ip fi man find comm=adsl3]}
:if ([ip fi man get [/ip fi man find comm=adsl4] disabled]=no) do={/ip fi man dis [/ip fi man find comm=adsl4]}
:if ([ip fi man get [/ip fi man find comm=adsl1 action=mark-connection] nth]!=1,1,0) do={/ip fi man set [/ip fi man find comm=adsl1 action=mark-connection] nth=1,1,0}
:if ([ip fi man get [/ip fi man find comm=adsl2 action=mark-connection] nth]!=1,1,1) do={/ip fi man set [/ip fi man find comm=adsl2 action=mark-connection] nth=1,1,1}
}
:if ($ii=3) do={
:if ([ip fi man get [/ip fi man find comm=adsl1] disabled]=yes) do={/ip fi man en [/ip fi man find comm=adsl1]}
:if ([ip fi man get [/ip fi man find comm=adsl2] disabled]=yes) do={/ip fi man en [/ip fi man find comm=adsl2]}
:if ([ip fi man get [/ip fi man find comm=adsl3] disabled]=yes) do={/ip fi man en [/ip fi man find comm=adsl3]}
:if ([ip fi man get [/ip fi man find comm=adsl4] disabled]=no) do={/ip fi man dis [/ip fi man find comm=adsl4]}
:if ([ip fi man get [/ip fi man find comm=adsl1 action=mark-connection] nth]!=2,3,0) do={/ip fi man set [/ip fi man find comm=adsl1 action=mark-connection] nth=2,3,0}
:if ([ip fi man get [/ip fi man find comm=adsl2 action=mark-connection] nth]!=2,3,1) do={/ip fi man set [/ip fi man find comm=adsl2 action=mark-connection] nth=2,3,1}
:if ([ip fi man get [/ip fi man find comm=adsl3 action=mark-connection] nth]!=2,3,2) do={/ip fi man set [/ip fi man find comm=adsl3 action=mark-connection] nth=2,3,2}
}
:if ($ii=4) do={
:if ([ip fi man get [/ip fi man find comm=adsl1] disabled]=yes) do={/ip fi man en [/ip fi man find comm=adsl1]}
:if ([ip fi man get [/ip fi man find comm=adsl2] disabled]=yes) do={/ip fi man en [/ip fi man find comm=adsl2]}
:if ([ip fi man get [/ip fi man find comm=adsl3] disabled]=yes) do={/ip fi man en [/ip fi man find comm=adsl3]}
:if ([ip fi man get [/ip fi man find comm=adsl4] disabled]=yes) do={/ip fi man en [/ip fi man find comm=adsl4]}
:if ([ip fi man get [/ip fi man find comm=adsl1 action=mark-connection] nth]!=3,4,0) do={/ip fi man set [/ip fi man find comm=adsl1 action=mark-connection] nth=3,4,0}
:if ([ip fi man get [/ip fi man find comm=adsl2 action=mark-connection] nth]!=3,4,1) do={/ip fi man set [/ip fi man find comm=adsl2 action=mark-connection] nth=3,4,1}
:if ([ip fi man get [/ip fi man find comm=adsl3 action=mark-connection] nth]!=3,4,2) do={/ip fi man set [/ip fi man find comm=adsl3 action=mark-connection] nth=3,4,2}
:if ([ip fi man get [/ip fi man find comm=adsl4 action=mark-connection] nth]!=3,4,3) do={/ip fi man set [/ip fi man find comm=adsl4 action=mark-connection] nth=3,4,3}
}
脚本可能有冗余,但是运行半个月表现良好。
[ 本帖最后由 171594765 于 2008-8-13 14:44 编辑 ] |
|