找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 11415|回复: 5

[脚本] 自动修改PCC参数

[复制链接]
发表于 2019-10-4 15:08:11 | 显示全部楼层 |阅读模式

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

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

×
以下是我在用的根据外网连接状况,自动修改PCC脚本,实测可以使用,但在运行中发现,当不满足脚本设定条件时,脚本也在执行,请大神请教下,也好造福大众.
{
:local status
:local i "3"
:local x "0"
:local y "0"
:local z "0"
:set x [:len [/interface pppoe-client find running=yes (name~"^tel")=yes]]
:set z [:len [/ip fir nat find action="src-nat" disabled=no chain=srcnat (comment~"^tel")=yes]]
:if ((($x<$i) && ($x<$z)) || (($x<$i) && ($x>$z))) do={
:for ii from=1 to=$i do={
:set status [/interface get [find name=("tel-".$ii)] running]
:if ($status=true) do={
/ip fir man set [find comment=("tel-".$ii)] per-connection-classifier=("both-addresses-and-ports:".$x."/".$y) disable=no;:set y ($y+1);/ip fir man set [find comment=("tel-".$ii)] disable=no;/ip fir man set [find comment=("tel-"."$ii$ii$ii")] disable=no;/ip fir nat set [find comment=("tel-".$ii)] disable=no} else={
/ip fir man set [find comment=("tel-".$ii)] disable=yes;/ip fir man set [find comment=("tel-"."$ii$ii$ii")] disable=yes;/ip fir nat set [find comment=("tel-".$ii)] disable=yes}}}
:if (($x=$i) && ($x>$z)) do={
:for ii from=1 to=$i do={
/ip fi man set [find comment=("tel-".$ii)] per-connection-classifier=("both-addresses-and-ports:".$x."/".$y) disable=no;:set y ($y+1);/ip fi man set [find comment=("tel-".$ii)] disable=no;/ip fir man set [find comment=("tel-"."$ii$ii$ii")] disable=no;/ip fir nat set [find comment=("tel-".$ii)] disable=no}}}
}



1.png
2.png
3.png
routeros
发表于 2019-10-4 22:17:57 | 显示全部楼层
本帖最后由 cspm333 于 2019-10-4 23:14 编辑

:local tel
:local con
:local dtor
:foreach i in=[/int pppoe-c find] do={
:local run [/int get $i running]
:if ($run) do={:set dtor ($dtor+1)}

:set tel "$tel,$[/int get $i name]"
:set con "$con,$run"
}
:set tel [:pick $tel 1 [:len $tel]]
:set con [:pick $con 1 [:len $con]]

:local ntor -1
:foreach v,i in=[:toarray $tel] do={
:local run [:pick [:toarray $con] $v]
:if ($run) do={:set ntor ($ntor+1)}
:local pcc "both-addresses-and-ports:$dtor/$ntor"

:local mid [/ip fi man find per-connection-classifier~"/" comment~"^$i"]
:local msw (![/ip fi man get $mid disabled])
:if (!$run && $msw) do={/ip fi man disable $mid}
:if ($run && (!$msw || [/ip fi man get $mid per-connection-classifier]!=$pcc)) do={
  /ip fi man set $mid per-connection-classifier=$pcc disabled=no}

:local nid [/ip fi nat find action=masquerade comment=$i]
:local nsw (![/ip fi nat get $nid disabled])
:if (!$run && $nsw) do={/ip fi nat disable $nid}
:if ($run && !$nsw) do={/ip fi nat enable $nid}
}

routeros
回复

使用道具 举报

 楼主| 发表于 2019-10-5 15:50:39 | 显示全部楼层
cspm333 发表于 2019-10-4 22:17
:local tel
:local con
:local dtor

干货满满,论坛有你更精彩,脚本始终运行的原因找到了,是我设定的一个参数不相符,导致条件一直满足!感谢
routeros
回复

使用道具 举报

发表于 2019-11-9 23:07:23 | 显示全部楼层
感谢大神 有没有单线多拨的断线修改PCC脚本
routeros
回复

使用道具 举报

发表于 2020-1-29 23:26:02 来自手机 | 显示全部楼层
真的好东西
routeros
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 21:14 , Processed in 0.058428 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

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