Get dhcp-client gateway

Hi

I use a script that checks 3 gateways (1 ADSL on the interface ether1-gateway and 2 Wi-Fi Links)

#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"]

this works, but the first gateway (currently 192.168.11.254) is a dhcp-client interface, so i’d like to get it in a variable instead of define it statically… something like

:local Gateways “$AdslGW,168.10.1,192.168.10.2”


i’ve tried

 :local AdslGW [ip dhcp-client get [find interface=ether1-gateway ] gateway ]
bad command name ip (line 1 column 16)

tried also

[admin@MikroTik] /ip route> :local currentGateway [ /ip dhcp-client get [/ip dhcp-client find status=bound ] gateway ]
[admin@MikroTik] /ip route> :put $currentGateway

i’m not familiar with mikrotik scripting, can someone help me, please?

thanks!

Should work with:
{
:local dhcpIP [/ip dhcp-client get [find interface=ether1] gateway];
:local Gateways “$dhcpIP,192.168.10.1,192.168.10.2”
:put $Gateways
}


Check with
:put [/ip dhcp-client get [find interface=ether1] gateway]


(in your case interface=ether1-gateway)

Please. I want script for disable. Or. Enable the activated Ethernet in Dhcp-client

Sent from my SM-N900 using Tapatalk