注册 登录
自由的生活_软路由 返回首页

xnsxcoolczh的个人空间 https://bbs.routerclub.com/?59750 [收藏] [复制] [分享] [RSS]

日志

pcc多线负载均衡自动撤换脚本

已有 1434 次阅读2011-6-15 23:56

脚本一:

:global status
:global linx
:global x
:global n
:global m
:set x 4
:set linx 0
:for i from=1 to="$x" do={
:set status [/interface get [/interface find name=("pppoe-out" . "$i")] running]
:if ("$status"=true) do={
:set linx ($linx + 1)
}}
:if ("$linx" > 1) do={
:set m "$linx"
:set n 0
:for i from=1 to="$x" do={
:set status [/interface get [/interface find name=("pppoe-out" . "$i")] running]
:if ("$status"=true) do={
/ip fir man set [/ip fir man find comment="$i"] per-connection-classifier=("both-addresses" . ":" . "$m" . "/" . "$n") disabled=no
:set n ($n + 1)
}
:if ($status != true) do={
/ip fir man set [/ip fir man find comment="$i"] disabled=yes
}}
}


脚本二:

:local pccstatus
:local status
:local pccold
:local pccnew
:local link
:local ncm
:local nrm
:local y
:local z
:local x
:set x 4
:set link 0
:for i from=1 to="$x" do={
:set status [/interface get [/interface find name=("pppoe-out" . "$i")] running]
:if ("$status" = true) do={
:set link ($link + 1)
}
}
:if ("$link" > 1) do={
:set z "$link"
:set y 0
:for i from=1 to="$x" do={
:set status [/interface get [/interface find name=("pppoe-out" . "$i")] running]
:set ncm ("adsl" . "$i" . "conn")
:set nrm ("ADSL" . "$i")
:if ("$status" = true) do={
:set pccnew ("both-addresses" . ":" . "$z" . "/" . "$y")
:set pccold [/ip firewall mangle get [ /ip firewall mangle find chain=bonding new-connection-mark="$ncm"] per-

connection-classifier]
:set pccstatus [/ip firewall mangle get [/ip firewall mangle find chain=bonding new-connection-mark="$ncm"] disable]
:if (("$pccnew" != $pccold) || ("$pccstatus" = true)) do={
/ip firewall mangle set [ /ip firewall mangle find chain=bonding new-connection-mark="$ncm"] per-connection-

classifier=$pccnew disabled=no
/ip firewall mangle set [ /ip firewall mangle find chain=bonding new-routing-mark="$nrm"] disabled=no
}
:set y ($y + 1)
} else {
:set pccstatus [/ip firewall mangle get [/ip firewall mangle find chain=bonding new-connection-mark="$ncm"] disable]
:if ("$pccstatus" = false) do={
/ip firewall mangle disable [ /ip firewall mangle find chain=bonding new-connection-mark="$ncm"]
/ip firewall mangle disable [/ip firewall mangle find chain=bonding new-routing-mark="$nrm"]
}
}
}
}
}


脚本三:

{
:local status
:local i "2"
:local x "0"
:local y "0"
:local z "0"
:set x [:len [/interface pppoe-client find running=yes>
:if ($x<$i) do={
:for ii from=1 to=$i do={
:set status [/interface get [find name=("pppoe-out".$ii)] running]
:if ($status=true) do={
/ip fir man set [find new-connection-mark=$ii] per-connection-classifier=("both-addresses:".$x."/".$y) disable=no;:set y ($y+1)} else={
/ip fir man set [find new-connection-mark=$ii] disable=yes}}}
:if ($x=$i) do={
:set z [:len [/ip fir man find action="mark-connection" disabled=yes chain=prerouting>
:if ($z>0) do={
:for ii from=1 to=$i do={
/ip fi man set [find new-connection-mark=$ii] per-connection-classifier=("both-addresses:".$x."/".$y) disable=no;:set y ($y+1)}}}}


路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

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

GMT+8, 2024-5-7 13:10 , Processed in 0.040066 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

返回顶部