I use a script that checks 3 gateways (1 ADSL on the interface ether1-gateway and 2 Wi-Fi Links)
Code: Select all
#set variables
:local pingcount 3
:local pingip 8.8.8.8
:local Gateways "192.168.11.254,168.10.1,192.168.10.2"
:local Gateway [:toarray $Gateways]
:if ([/ip route print count-only where dst-address="$pingip/32"]=0) do={/ip route add dst-address=($pingip) gateway=(192.168.1.254) comment="Gateway Check"};
:foreach k in $Gateway do={
#Test Gateways:
/ip route set [find dst-address="$pingip/32"] disabled=no gateway=$k comment="Checking Gateway $k ...";
:delay 1000ms;
:if ([/ip route get [find dst-address="$pingip/32"] gateway-status] = "$k unreachable") do={:log info ("Router $k not present or unconfigured")} else={
:local pingresult [/ping $pingip count=$pingcount];
# Gateway enable/disable:
:if ($pingresult=0) do={:foreach i in=[/ip route find gateway=$k] do={/ip route set $i disabled=yes}};
:if ($pingresult>0) do={:foreach i in=[/ip route find gateway=$k] do={:if ([/ip route get $i disabled]) do={/ip route set $i disabled=no}}};
:if ($pingresult=0) do={:log info ("Gateway $k Down! $pingresult / $pingcount")} else={:log info ("Gateway $k Up $pingresult / $pingcount")};
:delay 3000ms;
}
}
/ip route remove [find dst-address="$pingip/32"]
:local Gateways "$AdslGW,168.10.1,192.168.10.2"
i've tried
Code: Select all
:local AdslGW [ip dhcp-client get [find interface=ether1-gateway ] gateway ]
bad command name ip (line 1 column 16)
Code: Select all
[admin@MikroTik] /ip route> :local currentGateway [ /ip dhcp-client get [/ip dhcp-client find status=bound ] gateway ]
[admin@MikroTik] /ip route> :put $currentGateway
thanks!