找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 51|回复: 1

[脚本] 请大神们帮忙修改一下脚本。谢谢!

[复制链接]
发表于 前天 17:17 | 显示全部楼层 |阅读模式

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

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

×
以下rosv7版本 这个脚本多线路,只有路由表 打开或者关闭 出现不可用。没有反应。其他功能都正常。

请大神们帮忙修改一下。谢谢!

:local pccstatus
:local status
:local pccold
:local pccnew
:local link
:local ncm
:local nrm
:local y
:local z
:local x
:set x 4
#这里是adsl的数量
:set link 0
:for i from=1 to="$x" do={
    :set status [/interface get [/interface find  name=("PPPOE-ADSL-" . "$i")] running]
    :if ("$status" = true) do={
    :set link ($link + 1)
  }
}
:if ("$link" > 0) do={
    :set z "$link"
    :set y 0
    :for i from=1 to="$x" do={
         :set status [/interface get [/interface find  name=("PPPOE-ADSL-" . "$i")] running]
         :set ncm ("PCC_" . "$i")
#这里是连接标记
         :set nrm ("PCC_ROUT-" . "$i")
#这里是路由标记
         :if ("$status" = true) do={
                    :set pccnew ("both-addresses-and-ports" . ":" . "$z" . "/" . "$y")
                    :set pccold [/ip firewall mangle get [ /ip firewall mangle find chain=prerouting new-connection-mark="$ncm"] per-connection-classifier]
                    :set pccstatus [/ip firewall mangle get [/ip firewall mangle find chain=prerouting new-connection-mark="$ncm"] disable]
                    :if (("$pccnew" != $pccold) || ("$pccstatus" = true)) do={
                          /ip firewall mangle set [ /ip firewall mangle find chain=prerouting new-connection-mark="$ncm"] per-connection-classifier=$pccnew disabled=no
                          /ip firewall mangle set [ /ip firewall mangle find chain=prerouting new-routing-mark="$nrm"] disabled=no
                          /ip firewall mangle set [ /ip firewall mangle find chain=input new-connection-mark="$ncm"] per-connection-classifier=$pccnew disabled=no
                          /ip firewall mangle set [ /ip firewall mangle find chain=output new-routing-mark="$nrm"] disabled=no
                          /ip firewall nat set [/ip firewall nat find action=src-nat chain=srcnat out-interface="PPPOE-ADSL-" . "$i"] disabled=no
                          /ip route set [/ip route find dst-address="0.0.0.0/0" gateway="PPPOE-ADSL-" . "$i" routing-mark="$nrm"] disabled=no
                          /ip route set [/ip route find dst-address="0.0.0.0/0" gateway="PPPOE-ADSL-" . "$i" distance="$i"] disabled=no
                      }
             :set y ($y + 1)
          } else {
                  :set pccstatus [/ip firewall mangle get [/ip firewall mangle find chain=prerouting new-connection-mark="$ncm"] disable]
                  :if ("$pccstatus" = false) do={
                         /ip firewall mangle disable [ /ip firewall mangle find chain=prerouting new-connection-mark="$ncm"]
                         /ip firewall mangle disable [/ip firewall mangle find chain=prerouting new-routing-mark="$nrm"]
                         /ip firewall mangle disable [ /ip firewall mangle find chain=input new-connection-mark="$ncm"]
                         /ip firewall mangle disable [/ip firewall mangle find chain=output new-routing-mark="$nrm"]
                         /ip firewall nat disable [/ip firewall nat find action=src-nat chain=srcnat out-interface="PPPOE-ADSL-" . "$i"]
                         /ip route disable [/ip route find dst-address="0.0.0.0/0" gateway="PPPOE-ADSL-" . "$i" routing-mark="$nrm"]
                         /ip route disable [/ip route find dst-address="0.0.0.0/0" gateway="PPPOE-ADSL-" . "$i" distance="$i"]
             }
        }
    }
  }
}

routeros
发表于 18 分钟前 | 显示全部楼层

回帖奖励 +10 铜板


  1. {
  2. :local pccstatus
  3. :local status
  4. :local pccold
  5. :local pccnew
  6. :local link
  7. :local ncm
  8. :local nrm
  9. :local y
  10. :local z
  11. :local x
  12. :local pppoename "PPPOE-ADSL-"
  13. :set x 4
  14. #这里是adsl的数量
  15. :set link 0
  16. :for i from=1 to="$x" do={
  17.     :set status [/interface get [/interface find  name=($pppoename . $i)] running]
  18.     :if ("$status" = true) do={
  19.     :set link ($link + 1)
  20.   }
  21. }
  22. :if ("$link" > 0) do={
  23.     :set z "$link"
  24.     :set y 0
  25.     :for i from=1 to="$x" do={
  26.          :set status [/interface get [/interface find  name=($pppoename . $i)] running]
  27.          :set ncm ("PCC_" . "$i")
  28.          :set nrm ("PCC_ROUT-" . "$i")
  29.          #:if ([:len [/routing table find where name=$nrm]] = 0) do={
  30.          #/routing table add name=$nrm disabled=no
  31.          #}
  32.          :if ("$status" = true) do={
  33.                     :set pccnew ("both-addresses-and-ports" . ":" . "$z" . "/" . "$y")
  34.                     :set pccold [/ip firewall mangle get [ /ip firewall mangle find chain=prerouting new-connection-mark="$ncm"] "per-connection-classifier"]
  35.                     :set pccstatus [/ip firewall mangle get [/ip firewall mangle find chain=prerouting new-connection-mark="$ncm"] disable]
  36.                     :if (("$pccnew" != $pccold) || ("$pccstatus" = true)) do={
  37.                           /ip firewall mangle set [ /ip firewall mangle find chain=prerouting new-connection-mark="$ncm"] per-connection-classifier=$pccnew disabled=no
  38.                           /ip firewall mangle set [ /ip firewall mangle find chain=prerouting new-routing-mark="$nrm"] disabled=no
  39.                           /ip firewall mangle set [ /ip firewall mangle find chain=input new-connection-mark="$ncm"] per-connection-classifier=$pccnew disabled=no
  40.                           /ip firewall mangle set [ /ip firewall mangle find chain=output new-routing-mark="$nrm"] disabled=no
  41.                           /ip firewall nat set [/ip firewall nat find action=src-nat chain=srcnat out-interface=($pppoename . $i)] disabled=no
  42.                           /ip route set [/ip route find dst-address="0.0.0.0/0" gateway=($pppoename . $i) routing-table="$nrm"] disabled=no
  43.                           /ip route set [/ip route find dst-address="0.0.0.0/0" gateway=($pppoename . $i) distance="$i"] disabled=no
  44.                       }
  45.              :set y ($y + 1)
  46.           } else {
  47.                   :set pccstatus [/ip firewall mangle get [/ip firewall mangle find chain=prerouting new-connection-mark="$ncm"] disable]
  48.                   :if ("$pccstatus" = false) do={
  49.                          /ip firewall mangle disable [ /ip firewall mangle find chain=prerouting new-connection-mark="$ncm"]
  50.                          /ip firewall mangle disable [/ip firewall mangle find chain=prerouting new-routing-mark="$nrm"]
  51.                          /ip firewall mangle disable [ /ip firewall mangle find chain=input new-connection-mark="$ncm"]
  52.                          /ip firewall mangle disable [/ip firewall mangle find chain=output new-routing-mark="$nrm"]
  53.                          /ip firewall nat disable [/ip firewall nat find action=src-nat chain=srcnat out-interface=($pppoename . $i)]
  54.                          /ip route disable [/ip route find dst-address="0.0.0.0/0" gateway=($pppoename . $i) routing-table="$nrm"]
  55.                          /ip route disable [/ip route find dst-address="0.0.0.0/0" gateway=($pppoename . $i) distance="$i"]
  56.              }
  57.         }
  58.     }
  59.   }
  60. }
复制代码
routeros
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-8-2 23:02 , Processed in 0.202254 second(s), 14 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

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