Routeros脚本自动切换到备份线路教程

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Routeros脚本自动切换到备份线路教程
Routeros脚本自动切换到备份线路教程
{
#功能:判断连不上主线路,自动切换到备份线路
:loc outNamePx "pppoe-out"
:loc rundomName "ether1"
:gl randomservice
:if ([:tostr $randomservice] = "") do={:set randomservice 0} :foreach i in=[/int pptp-client find disabled=no running=no] do={
:local outname [/int pptp-client get $i name];
:local com [/int pptp-client get $i comment];
:local username [:pick $com 0 [find $com "--"]]
:put $username
#:local pro [/ppp sec get [find name=$username] profile]
:local ipip []
:foreach i in=[/ppp active find name=$username] do={
:local ipa [/ppp active get $i address]
:set ipip ($ipip,$ipa)
}
:set ipip [:pick $ipip 0]
:local ip ($ipip)
:set ip ($ip & ~0.0.0.255)
:set ip ($ip."/24")
:set ip [:pick $ip 0 [find $ip "0/24"]]
:set ip ($ip."254")
:local profilecomment [/ppp pro get [/ppp pro find local-address=$ip] comment]
:put $ip
#:local profilecomment [/ppp profile get [find name=$pro] comment]
:local connectList [:pick $profilecomment ([:find $profilecomment "<"]+1) [:find $profilecomment ">"] ] :set connectList [:toarray $connectList]
:local outLen2 [:len $connectList]
:local outNum2 ($randomservice % $outLen2)
:set connectList [:pick $connectList $outNum2]
:local connect [:pick $connectList 0 [:find $connectList "-"]] :local user [:pick $connectList ([:find $connectList "-"]+1) 10000]
:local pass ($user)
:if ($user~"zds") do={:set pass "1681688888"}
/int pptp-client set $outname disabled=yes
/int pptp-cl set [f name=$outname] connect-to=$connect disabled=no user=$user password=$pass comment=($username."--".$connectList."--自动切换备份线路") }
}
#统计每天最多在线多少个用户
{
:local nyr [/system clock get date]
:local yy ([:find jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec [:pick $nyr 0 3]]+1) :if ($yy<10) do={:set yy (0 . $yy)}
:set nyr ([:pick $nyr 7 11] . $yy . [:pick $nyr 4 6])
:local time [/system clock get time]
:set nyr ($nyr."-user")
:local lenactive [:len [/ppp active find]]
:local lennyr [:len [/ip fir layer7 find name=$nyr]]
:if ($lennyr=0) do={
/ip fir layer7 add name=$nyr regexp=$lenactive comment=$time } else={
:local regexp [/ip fir layer7 get [find name=$nyr] regexp]
:if ($lenactive>$regexp) do={
/ip fir layer7 set [find name=$nyr] regexp=$lenactive comment=$time }
}
}
#统计每天最大带宽
{
:local nyr [/system clock get date]
:local yy ([:find jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec [:pick $nyr 0 3]]+1) :if ($yy<10) do={:set yy (0 . $yy)}
:set nyr ([:pick $nyr 7 11] . $yy . [:pick $nyr 4 6])
:local time [/system clock get time]
:set nyr ($nyr."-traffic(/M)")
:loc rx
/interface monitor ether1 once do={:set rx $"rx-bits-per-second" }
:set rx ($rx/1000)
:set rx ($rx/1000)
:local lennyr [:len [/ip fir layer7 find name=$nyr]]
:if ($lennyr=0) do={
/ip fir layer7 add name=$nyr regexp=$rx comment=$time } else={
:local regexp [/ip fir layer7 get [find name=$nyr] regexp]
:if ($rx>$regexp) do={
/ip fir layer7 set [find name=$nyr] regexp=$rx
comment=$time }
}
}
#关闭没用用户使用的出口
{
:foreach k in=[/interface pptp-client find running=yes] do={ :local outname [/interface pptp-client get $k name]
:local namenum [:pick $outname 9 20]
:local lenmark [:len [/ip fir mangle find chain=prerouting action=mark-routing new-routing-mark=$namenum]] :local lenrule [:len [/ip route rule find table=$namenum]]
:if ($lenmark=0 && $lenrule=0) do={
/int pptp-client set $k dis=yes comment=""
:log error ("出口".$outname."没有用户使用暂时关闭")
}
}
}。

相关文档
最新文档