Community discussions

MikroTik App
 
User avatar
aacable
Member
Member
Topic Author
Posts: 435
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Get single IP from interface which have multiple IP' assigned

Wed Apr 10, 2019 10:31 am

I have a interface which have multiple IP's assigned. like
ether6: 1.1.1.1
ether6: 2.1.1.1

How can I get all IPs in single variable. like VAR="1.1.1.1 2.1.1.1" or if possible just single ip ?
 /ip address get [find interface="ether6"] address
& I get this error
invalid internal item number
 
User avatar
vecernik87
Forum Veteran
Forum Veteran
Posts: 882
Joined: Fri Nov 10, 2017 8:19 am

Re: Get single IP from interface which have multiple IP' assigned  [SOLVED]

Wed Apr 10, 2019 11:59 am

whole issue is, that your
[find interface="xxx"]
returns an array of interfaces..
All you need to do is pick one
/ip address get [:pick [find interface="ether6"] 0] address]

or if you want to test it in console, simply
:put [/ip address get [:pick [find interface="ether6"] 0] address]]
 
User avatar
aacable
Member
Member
Topic Author
Posts: 435
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: Get single IP from interface which have multiple IP' assigned

Wed Apr 10, 2019 12:02 pm

whole issue is, that your
[find interface="xxx"]
returns an array of interfaces..
All you need to do is pick one
/ip address get [:pick [find interface="ether6"] 0] address]
or if you want to test it in console, simply
:put [/ip address get [:pick [find interface="ether6"] 0] address]]
 
 :put [/ip address get [:pick [find interface="ether6"] 0] address]] 
Thank you it worked !
 
User avatar
vecernik87
Forum Veteran
Forum Veteran
Posts: 882
Joined: Fri Nov 10, 2017 8:19 am

Re: Get single IP from interface which have multiple IP' assigned

Wed Apr 10, 2019 12:59 pm

well, it depends if you want to use it in script or just display value in CLI. the
:put
command is like an "echo" or "print" in other languages - it displays content of variable.
If its gonna be used in some script, you will most likely want to use the value in some other command, because you can't really see what automated scripts print in console.

Who is online

Users browsing this forum: No registered users and 31 guests