From 3c491fe2c533dae2204e1abe047d12a3e4923680 Mon Sep 17 00:00:00 2001 From: Theenoro Date: Sat, 8 Oct 2022 16:28:44 +0200 Subject: [PATCH] =?UTF-8?q?=E2=80=9Esrc/change-defaultRoute.pl=E2=80=9C=20?= =?UTF-8?q?hinzuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/change-defaultRoute.pl | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/change-defaultRoute.pl diff --git a/src/change-defaultRoute.pl b/src/change-defaultRoute.pl new file mode 100644 index 0000000..2781af9 --- /dev/null +++ b/src/change-defaultRoute.pl @@ -0,0 +1,49 @@ +# for this you +# this script depends on 5 routes +# 1. with the comment "MAINGW" this will be always changed depends on if DSL is available +# 2. with comment "DSL" this is your route where normally all your traffic goes +# 3. 1.1.1.1 over DSL fixed +# 4. with comment "LTE" if ping to 1.1.1.1 fails +# 5. route to your uptime kuma, +# +# uptime kuma is externally hosted and only available over a vpn +# + + + +:local LanInterface ether1 + +:local PingTargetOne 1.1.1.1 +:local FailThreshholdOne 3 + +:global PingFailCountOne + +:local maingw [/ip route get [find comment="MAINGW"] gateway ]; +:local dslgw [/ip route get [find comment="DSL"] gateway ]; +:local ltegw [/ip route get [find comment="LTE"] gateway ]; + +:set $PingResult [ping 1.1.1.1 count=1] +:put $PingResult + +:if ($PingResult = 0) do={ + :if ($PingFailCountONE < ($FailTresholdOne+2)) do={ + :set $PingFailCountOne ($PingFailCountOne + 1) + :log warning "Ping to $PingTargetONE failed." + + :if ( PingFailCountOne >= $FailTreshold) do={ + :log warning "Change default route to LTE Backup!" + :log info "Change default route to LTE Backup!" + + /ip route set [find comment="MAINGW"] gateway=$ltegw + /ip route set [find comment="UPTIME_KUMA"] type=blackhole + } + } +} +:if ($PingResult = 1) do={ + :if ($PingFailCountOne > 0) do={ + :set PingFailCountOne 0 + :log info "Reset route to DSL" + /ip route set [find comment="MAINGW"] gateway=$dslgw + /ip route set [find comment="UPTIME_KUMA"] type=unicast + } +} \ No newline at end of file