Community discussions

MikroTik App
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

How to get routing table elements in route list

Fri Feb 03, 2023 10:11 am

Hello guys,
I wanted to know how to get the element routing table from the route list.
I tried something like this but it does not work:
:local a [/ip/route/get [find where gateway=x.x.x.x] routing-table];
Another problem is that I do not want the routing table "main" but I am using the same gateways for two list items.
Here a picture for better understanding.
Image
Any help would be appreciated:)
 
pe1chl
Forum Guru
Forum Guru
Posts: 10183
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to get routing table elements in route list

Fri Feb 03, 2023 11:12 am

Your syntax is wrong, try:
:local a [/ip/route/get [find where gateway=x.x.x.x and routing-table=yyyy];
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Re: How to get routing table elements in route list

Fri Feb 03, 2023 11:22 am

Your syntax is wrong, try:
:local a [/ip/route/get [find where gateway=x.x.x.x and routing-table=yyyy];
I forgot to say: I want to find out the the name of the routing-table over the route list. The only information i have is the gateway and it can not be the main-routing table.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10183
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to get routing table elements in route list

Fri Feb 03, 2023 11:29 am

then use routing-table!=main
I don't see the problem...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How to get routing table elements in route list

Fri Feb 03, 2023 11:30 am

Your syntax is wrong, try:
:local a [/ip/route/get [find where gateway=x.x.x.x and routing-table=yyyy];
no, the syntax is right, it want know the routing-table, if must be specified in find that mean that is already knowed...



This syntax is correct on v7(.7), but if more than one gateway is present, get returns an error because it cannot handle the array.
:local rt [/ip/route get [find where gateway=11.22.33.44 and routing-table!=main] routing-table]
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How to get routing table elements in route list

Fri Feb 03, 2023 11:38 am

I want to find out the the name of the routing-table over the route list.
The only information i have is the gateway and it can not be the main-routing table.

This do not do errors if multiple routes with same gateway (and not on main routing table) exist
/ip/route
{
    :local gway   1.2.3.4
    :local search [find where gateway=$gway and routing-table!=main]
    :local result ({})
    :foreach index in=$search do={
        :set $result ($result,[get $index routing-table])
    }
    :put $result
}
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Re: How to get routing table elements in route list

Fri Feb 03, 2023 12:25 pm

:local rt [/ip/route get [find where gateway=11.22.33.44 and routing-table!=main] routing-table]
Thank you very much. This is working good.

Who is online

Users browsing this forum: No registered users and 12 guests