Script Dos Lineas Isp
Script Dos Lineas Isp
3
# Auth: Lógico Software (@logico-dev)
# Date: 2018-10-06
# Based on: https://wiki.mikrotik.com/wiki/Failover_Scripting by Tomas Kirnak
# Released under MIT License (MIT)
# Copyright (c) 2018 Lógico Software <[email protected]>
# Please fill the gateway IPs (or interface names in case of PPP)
:local GatewayISP1 192.168.1.1
:local GatewayISP2 172.16.1.1
# Please fill how many ping failures are allowed before fail-over happends
:local FailTreshold 3
# This inicializes the PingFailCount variables, in case this is the 1st time the
script has ran
:if ([:typeof $PingFailCountISP1] = "nothing") do={:set PingFailCountISP1 0}
:if ([:typeof $LastPingOk] = "nothing") do={:set LastPingOk 1}
# Check ISP1
:set PingResult [ping $PingTarget count=1 interface=$InterfaceISP1]
:put $PingResult
}
}
} else={
:set PingFailCountISP1 4
}
} else={
:if ($LastPingOk = 0) do={
:set PingFailCountISP1 ($PingFailCountISP1 - 1)
:if ($PingFailCountISP1 = 1) do={
:foreach i in=[/ip route find gateway=$GatewayISP1 && static]
do=\
{/ip route set $i distance=1}
:foreach i in=[/ip route find gateway=$GatewayISP2 &&
static] do=\
{/ip route set $i distance=2}
:log warning "ISP1 is back"
:set PingFailCountISP1 ($PingFailCountISP1 - 1)
:set LastPingOk 1
}
} else={
:set PingFailCountISP1 0
}
}