Community discussions

MikroTik App
 
MrBZA
just joined
Topic Author
Posts: 4
Joined: Fri Jun 20, 2014 11:05 pm

get interface address not working in v6.48.2

Wed Apr 21, 2021 9:18 am

In v6.48.2 scripting the below returns "no such item"
:put [/ip address get value-name=address [find interface=ether1]]
Was working on 6.48.1 and older.
Any ideas as to what changed??
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: get interface address not working in v6.48.2

Wed Apr 21, 2021 1:29 pm

do not accept "strange" syntax?
:put [/ip address get [find where interface=ether1] address]
 
nostromog
Member Candidate
Member Candidate
Posts: 226
Joined: Wed Jul 18, 2018 3:39 pm

Re: get interface address not working in v6.48.2

Wed Apr 21, 2021 3:01 pm

In v6.48.2 scripting the below returns "no such item"
:put [/ip address get value-name=address [find interface=ether1]]
Was working on 6.48.1 and older.
Any ideas as to what changed??
"no such item" -> /ip address print where interface=ether1 returns nothing
"invalid internal item number" -> /ip address print where interface=ether1 returns more than one address
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: get interface address not working in v6.48.2

Wed Apr 21, 2021 3:05 pm

"no such item" -> /ip address print where interface=ether1 returns nothing

"invalid internal item number" -> /ip address print where interface=ether1 returns more than one address

???
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: get interface address not working in v6.48.2

Wed Apr 21, 2021 3:10 pm

AH... understand what you try to write:
:put [/ip address get [find where interface=ether1] address]
if interface has no IP assigned return "no such item",

if interface has multiple IP return "invalid internal item number",

if have exactly one IP, return the IP.
Last edited by rextended on Wed Apr 21, 2021 4:52 pm, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: get interface address not working in v6.48.2

Wed Apr 21, 2021 3:11 pm

For see if ether1 have any IP, first to all you must check if ether1 is part of some bridge, and then retrieve the IP of the bridge.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: get interface address not working in v6.48.2

Wed Apr 21, 2021 3:18 pm

for retrieve all IP on ether1 interface without error: (0 IP=empty array; 1 IP=array with 1 IP, more IP = array of IP)
:foreach k in=[/ip address find where interface=ether1] do={:put [/ip address get $k address]}

this not consider IP eventually assigned at the bridge, if ether1 is on bridge

:foreach k in=[/int bri port find where interface=ether1] do={:put [/int bri port get $k bridge]}
 
MrBZA
just joined
Topic Author
Posts: 4
Joined: Fri Jun 20, 2014 11:05 pm

Re: get interface address not working in v6.48.2

Wed Apr 21, 2021 4:41 pm

@nostromog
With some further digging, the error was indeed "invalid internal item number" and not "no such item", there were 2 IP's on the same interface.

@rextended
Thank you, will incorporate it into my script, problem solved!

Who is online

Users browsing this forum: No registered users and 19 guests