找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2500|回复: 1

[脚本] 多ADSL负载--掉线后自动修改/nth 请问以下脚是哪位大师所写?

[复制链接]
发表于 2011-10-15 17:07:56 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
: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
        }
}
routeros
 楼主| 发表于 2011-10-15 17:08:59 | 显示全部楼层
请知道的大师们回复一下。谢谢。
routeros
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2024-5-13 00:26 , Processed in 0.047158 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

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