Community discussions

MikroTik App
 
winnerke
newbie
Topic Author
Posts: 46
Joined: Sat Oct 07, 2017 9:35 am

Scripting distance of routes

Mon Jun 24, 2019 6:11 pm

I would like to get the distance of a route for scripting purpose.

something like :

if([/ip route get "distance of a route"] = 5 ) do={
:log error "distance is 5";
}

but i can't get any command that provides me a distance of a route.
 
winnerke
newbie
Topic Author
Posts: 46
Joined: Sat Oct 07, 2017 9:35 am

Re: Scripting distance of routes

Mon Jul 08, 2019 3:12 pm

BUMP
 
andriys
Forum Guru
Forum Guru
Posts: 1526
Joined: Thu Nov 24, 2011 1:59 pm
Location: Kharkiv, Ukraine

Re: Scripting distance of routes

Mon Jul 08, 2019 3:25 pm

Try this:
:if ([/ip route get [find <your_search_criteria_goes_here>] distance] = 5) do={
    ...
}
 
winnerke
newbie
Topic Author
Posts: 46
Joined: Sat Oct 07, 2017 9:35 am

Re: Scripting distance of routes

Tue Jul 09, 2019 5:40 pm

Try this:
:if ([/ip route get [find <your_search_criteria_goes_here>] distance] = 5) do={
    ...
}
This does not work.

Tried the following :
:if ([/ip route get [find gateway=x.x.x.x] distance] = 3) do={
    :log error "test2"
}
It keeps logging test2, no matther what distance i put in the if/else statement.
 
2frogs
Forum Veteran
Forum Veteran
Posts: 713
Joined: Fri Dec 03, 2010 1:38 am

Re: Scripting distance of routes

Tue Jul 09, 2019 7:45 pm

Spacing maybe!?!? This works for me:
:if ([/ip route [find gateway=x.x.x.x] distance]=2) do={:log error “True”}
 
winnerke
newbie
Topic Author
Posts: 46
Joined: Sat Oct 07, 2017 9:35 am

Re: Scripting distance of routes

Tue Jul 09, 2019 11:10 pm

Spacing maybe!?!? This works for me:
:if ([/ip route [find gateway=x.x.x.x] distance]=2) do={:log error “True”}
This also does not work for me.
 
2frogs
Forum Veteran
Forum Veteran
Posts: 713
Joined: Fri Dec 03, 2010 1:38 am

Re: Scripting distance of routes  [SOLVED]

Wed Jul 10, 2019 3:05 am

Is x.x.x.x a unique ID or do you have multiple with gateway=x.x.x.x?

Copy and paste the following in Terminal:
/ip route add dst-address=1.2.3.4/32 gateway=1.2.3.4 distance=5;
:if ([/ip route get [find gateway=1.2.3.4] distance]=5) do={:put "True"} else={:put "False"};
##Should have output of "True" since distance is 5;
/ip route set [find gateway=1.2.3.4] distance=6;
:if ([/ip route get [find gateway=1.2.3.4] distance]=5) do={:put "True"} else={:put "False"};
##Should have output of "False" since distance is 6;
:if ([/ip route get [find gateway=1.2.3.4] distance]=6) do={:put "True"} else={:put "False"};
##Should have output of True since IF/ELSE and distance is 6;
Should look like this!
route_distance.PNG
You do not have the required permissions to view the files attached to this post.
 
winnerke
newbie
Topic Author
Posts: 46
Joined: Sat Oct 07, 2017 9:35 am

Re: Scripting distance of routes

Wed Jul 10, 2019 6:03 pm

Is x.x.x.x a unique ID or do you have multiple with gateway=x.x.x.x?

Copy and paste the following in Terminal:
/ip route add dst-address=1.2.3.4/32 gateway=1.2.3.4 distance=5;
:if ([/ip route get [find gateway=1.2.3.4] distance]=5) do={:put "True"} else={:put "False"};
##Should have output of "True" since distance is 5;
/ip route set [find gateway=1.2.3.4] distance=6;
:if ([/ip route get [find gateway=1.2.3.4] distance]=5) do={:put "True"} else={:put "False"};
##Should have output of "False" since distance is 6;
:if ([/ip route get [find gateway=1.2.3.4] distance]=6) do={:put "True"} else={:put "False"};
##Should have output of True since IF/ELSE and distance is 6;
Indeed this works on my main Mikrotik, but not on the other one.
When running this , i get "invalid internal item number"
 
winnerke
newbie
Topic Author
Posts: 46
Joined: Sat Oct 07, 2017 9:35 am

Re: Scripting distance of routes

Wed Jul 10, 2019 6:31 pm

This worked for me :

:if ([/ip route get [:pick [find gateway=x.x.x.x] 0] distance]=1) do={:put "True"} else={:put "False"}

this because i had multiple routes with the same gateway as you guys said.

Thanks !

Who is online

Users browsing this forum: No registered users and 12 guests