|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
×
:global NewIP
:global OldIP
:global Count
:global IsRun
:global Runid
:global Icount
:global Mainid
:global Mainip
:global Status
:global MainKey
:global MainCache
:global RuningCount
:global NewNthCache
:global OldNthCache
:set Count 9
:set Icount 0
:set Runid(a,a)
:set MainKey false
:set RuningCount 0
:set Mainip [/ip rou get [/ip rou find distance=1] gateway]
:set Mainid [/ip rou get [/ip rou find distance=1] comment]
:for i from=1 to=$Count do={
:set Status [/int get [/int find name=("pppoe-out" . $i)] running]
:set IsRun [/ip fir man get [/ip fir man find comment=("route-" . $i)] disabled]
:if ($Status=true) do={
:set RuningCount ($RuningCount + 1)
:set Runid ($Runid . $i)
:set NewIP [/ip address get [/ip address find dynamic=yes interface=("pppoe-out" . $i)] address]
:set NewIP [:pick $NewIP 0 [:find $NewIP "/"]]
:set OldIP [/ip address get [/ip address find dynamic=no interface=("pppoe-out" . $i)] address]
:set OldIP [:pick $OldIP 0 [:find $OldIP "/"]]
:if ($NewIP != $OldIP) do={
/ip add set [/ip add find comment=("adsl-" . $i)] address=$NewIP network=$NewIP broadcast=$NewIP
/ip rou set [/ip rou find comment=("adsl-" . $i)] gateway=$NewIP
/ip fir nat set [/ip fir nat find comment=("adsl-" . $i)] to-addresses=$NewIP
}
:if ($IsRun = true) do={
/ip fir man set [/ip fir man find comment=("route-" . $i)] disabled=no
/ip fir man set [/ip fir man find comment=("conn-" . $i)] disabled=no
/ip fir nat set [/ip fir nat find comment=("adsl-" . $i)] disabled=no
/ip rou set [/ip rou find comment=("adsl-" . $i)] disabled=no
:log info ( "第<" . $i . ">号网络线路故障恢复,分流开启!" . [/sys cl get date] . " " . [/sys cl get time] . "检测")
}
} else={
:if ($IsRun != true) do={
/ip fir man set [/ip fir man find comment=("route-" . $i)] disabled=yes
/ip fir man set [/ip fir man find comment=("conn-" . $i)] nth=0,0,0
/ip fir man set [/ip fir man find comment=("conn-" . $i)] disabled=yes
/ip fir nat set [/ip fir nat find comment=("adsl-" . $i)] disabled=yes
/ip rou set [/ip rou find comment=("adsl-" . $i)] disabled=yes
:log info ( "第<" . $i . ">号网络线路出现故障,分流关闭!" . [/sys cl get date] . " " . [/sys cl get time] . "检测")
}
}
}
:set RuningCount ($RuningCount - 1)
:foreach i in=$Runid do={
:if ($i != a) do={
:set OldNthCache [/ip fir man get [/ip fir man find comment=("conn-" . $i)] nth]
:set NewNthCache ($RuningCount . , . 1 . , . $Icount)
:if ($OldNthCache != $NewNthCache) do={
/ip fir man set [/ip fir man find comment=("conn-" . $i)] nth=$NewNthCache
:log info ( "第<" . $i . ">号网络线路修改分流设置成功!" . [/sys cl get date] . " " . [/sys cl get time] . "检测")
}
:set Icount ($Icount + 1)
}
:if ($Mainid != $i) do={
:if ($MainKey != true) do={
:set MainKey false
}
} else={
:set MainKey true
}
}
:if ($MainKey != true) do={
:set MainCache [:pick $Runid 2 3]
:set NewIP [/ip address get [/ip address find dynamic=yes interface=("pppoe-out" . $MainCache)] address]
:set NewIP [:pick $NewIP 0 [:find $NewIP "/"]]
:if ($Mainip != $NewIP) do={
:log info ( "默认网关检测失败,默认网关转换成<" . $MainCache . ">号线路" . [/sys cl get date] . " " . [/sys cl get time] . "检测")
/ip rou set [/ip route find distance=1] comment = $MainCache
/ip rou set [/ip rou find comment=$MainCache] gateway=$NewIP
}
} else={
:set NewIP [/ip address get [/ip address find dynamic=yes interface=("pppoe-out" . $Mainid)] address]
:set NewIP [:pick $NewIP 0 [:find $NewIP "/"]]
:if ($Mainip != $NewIP) do={
/ip rou set [/ip route find distance=1] comment = $Mainid
/ip rou set [/ip rou find comment=$Mainid] gateway=$NewIP
}
} |
|