Community discussions

MikroTik App
 
pentoz
just joined
Topic Author
Posts: 1
Joined: Mon Nov 30, 2015 12:13 pm

Get dhcp-client gateway

Mon Nov 30, 2015 12:26 pm

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!
 
User avatar
PaulsMT
MikroTik Support
MikroTik Support
Posts: 282
Joined: Tue Feb 10, 2015 3:21 pm

Re: Get dhcp-client gateway

Mon Nov 30, 2015 5:42 pm

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)
 
aboyomna2006
just joined
Posts: 12
Joined: Mon Jun 27, 2016 4:29 am

Re: Get dhcp-client gateway

Mon Jun 27, 2016 4:32 am

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

Sent from my SM-N900 using Tapatalk

Who is online

Users browsing this forum: abbio90 and 18 guests