Community discussions

MikroTik App
 
Josephny
Member
Member
Topic Author
Posts: 434
Joined: Tue Sep 20, 2022 12:11 am

Invalid internal item number

Sat Nov 26, 2022 2:11 pm

I get an "invalid internal item number" error when I try to run this script:

{
	:local ip
	/interface bridge host 
	:foreach ID in=[find] do={
		:local inf [get $ID interface]
		:local mac [get $ID mac-address]
		:local idmac [/ip arp find mac-address="$mac"]
		:if ([:len $idmac] > 0) do={
			:set ip [/ip arp get $idmac address]
			:put "interface=$inf mac=$mac ip=$ip"
		}
	}
}

Anyone know what I can do to fix it?

Thanks!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Invalid internal item number

Sat Nov 26, 2022 2:49 pm

/interface bridge host
:foreach item in=[find] do={
    :local iface  [get $item interface]
    :local macadd [get $item mac-address]
    :local idmac  [/ip arp find where mac-address=$macadd]
    :if ([:len $idmac] = 1) do={
        :local ifip [/ip arp get $idmac address]
        :put   "interface=$iface mac=$macadd ip=$ifip"
    }
}

nice to see that ; ; ; ; and (""."".""."") is not used, very well!!

useless local ip, if the script must not interact with other parts
do not use reserved words, or like so, for variables names
missing where
useless quoted $mac
find can give more than one IP by same MAC address
get not work with array, only with only one element array (of one ID) or ID
> 0 go to = 1, if more than one is present, must be used again a :foreach itm in=$idmac cycle
Can still do error if ARP entry is dynamically removed betwen the two "/ip arp" instructions because get not find the entry
 
Josephny
Member
Member
Topic Author
Posts: 434
Joined: Tue Sep 20, 2022 12:11 am

Re: Invalid internal item number

Sat Nov 26, 2022 3:28 pm

I certainly did not mean to take credit for authoring this script. In fact, I can barely understand it.

It came from:

viewtopic.php?t=161215

That said, as always, I greatly appreciate your help, but don't understand what you mean or how to eliminate the rror.
 
Josephny
Member
Member
Topic Author
Posts: 434
Joined: Tue Sep 20, 2022 12:11 am

Re: Invalid internal item number

Sun Nov 27, 2022 12:11 pm

Would you mind showing how to fix this?

Thank you
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Invalid internal item number

Sun Nov 27, 2022 4:41 pm

You still have "invalid ..." error also with my version?
 
Josephny
Member
Member
Topic Author
Posts: 434
Joined: Tue Sep 20, 2022 12:11 am

Re: Invalid internal item number

Sun Nov 27, 2022 5:29 pm

You still have "invalid ..." error also with my version?
Your version works -- sorry about my stupid question.

Thank you very much.

Now I will go and figure out why it works and how to use find/get/where!

Who is online

Users browsing this forum: No registered users and 11 guests