找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 68872|回复: 272

[负载平衡] 亮一下我写的小垃圾脚本~ADSL多线自动更改NTH (再发 3.0)

  [复制链接]
发表于 2010-5-13 07:03:39 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 zooyo 于 2011-2-9 19:36 编辑

本脚本集 ADSL 多线掉线后自动刷新IP~自动修改NTH值~默认网关线路出错后自动更换默认网关~默认网关更新同步更新DDNS 于一身~~
主要方便大家~~高手一笑而过就行了~小月~67088833

新版本在2.9.27下测试所有功能正常~~
3.X下未测试~~哪位兄弟测试过的请发布一下测试结果~~

3.X  and 2.9 小修改

  1. #自动换IP的脚本
  2. #带NTH修改功能,带自动修改默认网关功能 FOR 2.9.X and 3.0 V2.0
  3. #默认路由必须手动添加~默认路由的说明必须为数字!默认路由必须添加main路由标记
  4. #本版本脚本刚刚完成~未经测试~如有BUG请原谅~欢迎大虾们批评指正 小月QQ:67088833
  5. #开启SRC反转的全局NAT反转标识必须为GetNat
  6. #更多功能后期敬请等待 :global rosVer ""
  7. :global NewIP ""
  8. :global OldIP ""
  9. :global Count ""
  10. :global IsRun ""
  11. :global IsNat ""
  12. :global Runid ""
  13. :global BakTag ""
  14. :global RouTag ""
  15. :global ConTag ""
  16. :global AccTag ""
  17. :global NatTag ""
  18. :global IsSRou ""
  19. :global IsDDNS ""
  20. :global Icount ""
  21. :global Mainid ""
  22. :global Mainip ""
  23. :global Status ""
  24. :global Nthcon ""
  25. :global IntName ""
  26. :global MainKey ""
  27. :global DDNSName ""
  28. :global DDNSUser ""
  29. :global DDNSPass ""
  30. :global MainCache ""
  31. :global IsDefGetWay ""
  32. :global RuningCount ""
  33. :global NewNthCache ""
  34. :global OldNthCache ""
  35. #修改路由版本 false 为 2.9.x true为3.x
  36. :set ROSVer true
  37. #修改下方线路数量
  38. :set Count 5
  39. #修改下方接口名称
  40. :set IntName "ADSL-"
  41. #修改下方连接游标名称
  42. :set ConTag "Con-"
  43. #修改下方封包游标名称
  44. :set BakTag "Rou-"
  45. #修改下方静态IP名称
  46. :set AccTag "ADSL-"
  47. #修改下方NAT游标名称
  48. :set NatTag "ADSL-"
  49. #修改下方路由表名称
  50. :set RouTag "ADSL-"
  51. #是否为静态路由表
  52. :set IsSRou true
  53. #是否使用 SRCNAT 反转,使用MASQUERADED的朋友这里要设置false 要不会出错~!
  54. :set IsNat true
  55. #是否开启自动修改默认网关功能
  56. :set IsDefGetWay true
  57. #是否开启DDNS更新功能(不开启修改默认网关功能无效)
  58. :set IsDDNS true
  59. #动态域名
  60. :set DDNSName "xiaoyue.changeip.com"
  61. #用户名称
  62. :set DDNSUser "sadking"
  63. #用户密码
  64. :set DDNSPass "********"
  65. #以下设置不熟悉脚本者不要乱改动
  66. :if ($RosVer) do={
  67. :set Runid ("a","a")
  68. :set Nthcon ","
  69. :set Icount 1
  70. } else={
  71. :set Runid (a,a)
  72. :set Nthcon ",1,"
  73. :set Icount 0
  74. }
  75. :set MainKey false
  76. :set RuningCount 0
  77. :set Mainip [/ip rou get [/ip rou find distance=1 routing-mark="main"] gateway]
  78. :set Mainid [/ip rou get [/ip rou find distance=1 routing-mark="main"] comment]
  79. :for i from=1 to=$Count  do={
  80. :set Status [/int get [/int find name=($IntName . $i)] running]
  81. :set IsRun [/ip fir man get [/ip fir man find comment=($BakTag . $i)] disabled]
  82. :if ($Status) do={
  83. :set RuningCount ($RuningCount + 1)
  84. :if ($RosVer) do={
  85. :set Runid ($Runid + $i)
  86. } else={
  87. :set Runid ($Runid . $i)
  88. }
  89. :set NewIP [/ip add get [/ip add find dynamic=yes interface=($IntName . $i)] address]
  90. :set OldIP [/ip add get [/ip add find dynamic=no interface=($IntName . $i)] address]
  91. :set NewIP [:pick $NewIP 0 [:find $NewIP "/"]]
  92. :set OldIP [:pick $OldIP 0 [:find $OldIP "/"]]
  93. :if ($NewIP != $OldIP) do={
  94. /ip add set [/ip add find comment=($AccTag . $i)] address=$NewIP network=$NewIP broadcast=$NewIP
  95. :if (!$IsSRou) do={/ip rou set [/ip rou find comment=($RouTag . $i)] gateway=$NewIP}
  96. :if ($IsNat) do={/ip fir nat set [/ip fir nat find comment=($NatTag . $i)] to-addresses=$NewIP}
  97. }
  98. :if ($IsRun) do={
  99. /ip fir man set [/ip fir man find comment=($BakTag . $i)] disabled=no
  100. /ip fir man set [/ip fir man find comment=($ConTag . $i)] disabled=no
  101. :if ($IsNat) do={/ip fir nat set [/ip fir nat find comment=($NatTag . $i)] disabled=no}
  102. :if (!$IsSRou) do={/ip rou set [/ip rou find comment=($RouTag . $i)] disabled=no}
  103. :log info ( "第<" . $i . ">号网络线路故障恢复,分流开启!" . [/sys cl get date] . " " . [/sys cl get time] . "检测")
  104. }
  105. } else={
  106. :if (!$IsRun) do={
  107. /ip fir man set [/ip fir man find comment=($BakTag . $i)] disabled=yes
  108. #/ip fir man set [/ip fir man find comment=($ConTag . $i)] nth=0,0,0
  109. /ip fir man set [/ip fir man find comment=($ConTag . $i)] disabled=yes
  110. :if ($IsNat) do={/ip fir nat set [/ip fir nat find comment=($NatTag . $i)] disabled=yes}
  111. :if (!$IsSRou) do={/ip rou set [/ip rou find comment=($RouTag . $i)] disabled=yes}
  112. :log info ( "第<" . $i . ">号网络线路出现故障,分流关闭!" . [/sys cl get date] . " " . [/sys cl get time] . "检测")
  113. }
  114. }
  115. }
  116. :if (!$RosVer) do={:set RuningCount ($RuningCount - 1)}
  117. :foreach i in=$Runid do={
  118. :if ($i != "a") do={
  119. :set OldNthCache [/ip fir man get [/ip fir man find comment=($ConTag . $i)] nth]
  120. :set NewNthCache ($RuningCount . $Nthcon . $Icount)
  121. :if ($OldNthCache != $NewNthCache) do={
  122. /ip fir man set [/ip fir man find comment=($ConTag . $i)] nth=$NewNthCache
  123. :log info ( "第<" . $i . ">号网络线路修改分流设置成功!" . [/sys cl get date] . " " . [/sys cl get time] . "检测")
  124. }
  125. :set Icount ($Icount + 1)
  126. }
  127. :if ($IsDefGetWay) do={
  128. :if ($Mainid != $i) do={
  129. :if ($MainKey != true) do={
  130. :set MainKey false
  131. }
  132. } else={
  133. :set MainKey true
  134. }
  135. }
  136. }
  137. :if ($IsDefGetWay) do={
  138. :if (!$MainKey) do={
  139. :set MainCache [:pick $Runid 2 3]
  140. :if (!$IsSRou) do={
  141. :set NewIP [/ip add get [/ip address find dynamic=yes interface=($IntName . $MainCache)] address]
  142. :set NewIP [:pick $NewIP 0 [:find $NewIP "/"]]
  143. } else={
  144. :set NewIP [/ip add get [/ip address find dynamic=yes interface=($IntName . $MainCache)] network]
  145. }
  146. :if ($Mainip != $NewIP) do={
  147. :log info ( "默认网关检测失败,默认网关转换成<" . $MainCache . ">号线路" . [/sys cl get date] . " " . [/sys cl get time] . "检测")
  148. /ip rou set [/ip rou find distance=1 routing-mark="main"] comment= $MainCache
  149. /ip rou set [/ip rou find comment=$MainCache] gateway=$NewIP
  150. :if ($IsNat) do={/ip fir nat set [/ip fir nat find comment="GetNat"] to-addresses=$NewIP}
  151. :if ($IsDDNS) do={/tool dns-update name=$DDNSName address=$NewIP key-name=$DDNSUser key=$DDNSPass}
  152. }
  153. } else={
  154. :set NewIP [/ip add get [/ip add find dynamic=yes interface=($IntName . $Mainid)] address]
  155. :set NewIP [:pick $NewIP 0 [:find $NewIP "/"]]
  156. :if ($Mainip != $NewIP) do={
  157. /ip rou set [/ip rou find distance=1 routing-mark="main"] comment= $Mainid
  158. /ip rou set [/ip rou find comment=$Mainid] gateway=$NewIP
  159. :if ($IsNat) do={/ip fir nat set [/ip fir nat find comment="GetNat"] to-addresses=$NewIP}
  160. :if ($IsDDNS) do={/tool dns-update name=$DDNSName address=$NewIP key-name=$DDNSUser key=$DDNSPass}
  161. }
  162. }
  163. }
复制代码
2.9.x
NTH2.9.27.rar (1.61 KB, 下载次数: 160)
3.x and 2.9.x
NTH.rar (1.72 KB, 下载次数: 148)
小修改
NTHsp1.rar (1.75 KB, 下载次数: 181)
routeros
发表于 2010-5-13 07:08:40 | 显示全部楼层
学习了
routeros
回复

使用道具 举报

发表于 2010-5-13 07:49:16 | 显示全部楼层
ddddddddddddddddd
routeros
回复

使用道具 举报

发表于 2010-5-13 08:25:41 | 显示全部楼层
学习...
routeros
回复

使用道具 举报

发表于 2010-5-13 09:48:57 | 显示全部楼层
routeros
回复

使用道具 举报

发表于 2010-5-13 09:54:36 | 显示全部楼层
routeros
回复

使用道具 举报

发表于 2010-5-13 09:55:22 | 显示全部楼层
学习...
routeros
回复

使用道具 举报

发表于 2010-5-13 13:02:32 | 显示全部楼层
routeros
回复

使用道具 举报

发表于 2010-5-13 13:56:55 | 显示全部楼层
顶一下!!!!!
routeros
回复

使用道具 举报

发表于 2010-5-13 14:39:32 | 显示全部楼层
看看
routeros
回复

使用道具 举报

发表于 2010-5-13 14:53:52 | 显示全部楼层
看看好用不,不知道能不能用在3.2呢?
routeros
回复

使用道具 举报

发表于 2010-5-13 15:35:35 | 显示全部楼层
学习学习!
routeros
回复

使用道具 举报

发表于 2010-5-13 15:50:22 | 显示全部楼层
学习了。。。
routeros
回复

使用道具 举报

发表于 2010-5-13 16:49:15 | 显示全部楼层
本帖最后由 WGHBOY 于 2010-5-13 16:57 编辑

太长了吧 t.jpg nth4.jpg 以上为4线nth脚本,3.x
routeros
回复

使用道具 举报

发表于 2010-5-13 17:22:15 | 显示全部楼层
顶一下!!!!!
routeros
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-1 11:51 , Processed in 0.171889 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

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