ROS/PPPOE重拔脚本

我家里使用的电信的光宽带,有时候手机欠费了,就无法上网了,但是还是会拔上号,这个时候交了手机费,就必须重启路由或手动断线重拔,通过下面这个脚本,每10分钟运行一次,一但PING不通就立即断线重拔,这个是PING百度的。

{
:local newaddress
:local newnetwork
:local assignip
:local status
:local pppoestatus
:local pppoeup
:local pppoeupcount
:local pppoedown
:local pppoedowncount
##################
:local x 2
#---线路数请更改使用
##################
:set x [len [interface find type=pppoe-out]]
:set pppoeupcount 0
:set pppoedowncount 0
:for i from=1 to=$x do={
:set status [interface get [find  name=("pppoe-out" . $i)] running]
:if ($status=true) do={
:set newnetwork [ip address get [/ip address find dynamic=yes interface=("pppoe-out" . $i)] network]
:set pppoestatus [ping www.baidu.com count=2 interface=("pppoe-out" . $i)]
:if ($pppoestatus=1) do={
:log info ("pppoe-out". $i.rebooting......)
:beep
:int pppoe-client disable ("pppoe-out" . $i)
:delay 2
:int pppoe-client enable ("pppoe-out" . $i)
:delay 5
:if ($pppoedowncount=0) do={set pppoedown [($pppoedown ."pppoe-out" . $i)]}
:set pppoedowncount ($pppoedowncount + 1)
   }
:if ($pppoestatus=1) do={
:if ($pppoeupcount=0) do={set pppoeup [($pppoeup ."pppoe-out" . $i)]}
:set pppoeupcount ($pppoeupcount + 1)
   }
:set newaddress [ip address get [/ip address find dynamic=yes interface=("pppoe-out" . $i)] address]
  }
}
}



感觉这个脚本更简单好用 

{

:local interface [/interface find name=pppoe-out1]

:if ([:ping count=4 222.222.222.222]<1) do={

/interface disable $interface

:delay 2s 

/interface enable $interface

:log info "pppoe-out1端口重启完成"

} else={

:log info "地址通pppoe-out1不需要重启"

}

}