Community discussions

MikroTik App
 
balanila
just joined
Topic Author
Posts: 16
Joined: Sun Aug 25, 2013 12:45 pm
Location: Moldova, Chishinev

How to get members of interface list

Thu Sep 10, 2020 1:21 pm

Hello everyone!
Please help me.
I have static address list name=WAN
I need to get members of address list WAN
I have two interfaces in the list WAN: ether1 and vlan interface "Internet"
I tried to get with command:
:local interfaces [/interface list member find list=WAN]
but I got like this: *23;*24

Please, help me, how to get members of interface list?
Thank you!
 
al3xeezer
just joined
Posts: 22
Joined: Thu Feb 27, 2020 11:46 am

Re: How to get members of interface list

Thu Sep 10, 2020 1:42 pm

If you want to get the interface's names you can do this:
:local interfaces [/interface list member find list=WAN];
:foreach interface in=$interfaces do={
	:put [/interface get $interface name]
}

In the code I only print them, but you can store the values in a second array or so.
 
balanila
just joined
Topic Author
Posts: 16
Joined: Sun Aug 25, 2013 12:45 pm
Location: Moldova, Chishinev

Re: How to get members of interface list

Thu Sep 10, 2020 3:11 pm

If you want to get the interface's names you can do this:
:local interfaces [/interface list member find list=WAN];
:foreach interface in=$interfaces do={
	:put [/interface get $interface name]
}
In the code I only print them, but you can store the values in a second array or so.
Thank you for reply.
But very strange.
After command /interface list member find list=WAN I got answer *23;*24.
If I manually in the terminal type, as example, :put [/interface get *24 name] I got empty answer. Without "*" I got interface name, but this interface doesn't have list "WAN". Interface 23 is a cap interface, 24 is pptp interface.
Byt in my list WAN interface's .id is: 0 and 16 without "*"
 
al3xeezer
just joined
Posts: 22
Joined: Thu Feb 27, 2020 11:46 am

Re: How to get members of interface list  [SOLVED]

Thu Sep 10, 2020 4:39 pm

Did a bit of testing and I came up with this:
:foreach interface in=[/interface list member print as-value where list=WAN] do={:put ($interface->"interface")}
 
balanila
just joined
Topic Author
Posts: 16
Joined: Sun Aug 25, 2013 12:45 pm
Location: Moldova, Chishinev

Re: How to get members of interface list

Thu Sep 10, 2020 4:45 pm

Did a bit of testing and I came up with this:
:foreach interface in=[/interface list member print as-value where list=WAN] do={:put ($interface->"interface")}
Wow!
It's works!
Thank you very much!
I don't know why mikrotik doesn't make answer by default with "name" of interface on request /interface list member find list=WAN ...
Will be better to recieve name by default, not id of interface.
Thank you!
Have a great day!

Who is online

Users browsing this forum: No registered users and 5 guests