Community discussions

MikroTik App
 
User avatar
CyberTod
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Jan 25, 2012 10:23 am

Get variable from registration-table problem

Mon Jan 06, 2014 7:37 pm

Hello,

I have written a very small script a while ago and it was working properly in v5. Or maybe I didn't try it well enough. But here is the problem :

:local currentip [/interface wireless registration-table get [find where mac-address=$clientmac] value-name=last-ip];

This part of the script should get the last-ip of an entry in the registration table and that works. It does get the ip address.
But it works correctly only if this mac address is present in the registration table.
I think that when 'find where' statement is not fulfilled it should return a blank string, but instead it takes the 'last-ip' of the first result from the table and assigns it to the variable.
Can anyone tell me why is this behaving this way and maybe a way to fix it ?

P.S. I am pretty certain that I did some tests for the case that this mac is not present back in v5, because I am checking for blank string later in the script :

... and [:len $currentip] > 0

Now the board is using latest v6.7 routeros
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Get variable from registration-table problem

Tue Jan 07, 2014 6:34 pm

If you paste this into a terminal with an an existing MAC, it should return 1, and a non-existing should return 0.

ros code

:put [:len [/interface wireless registration-table find where mac-address=00:0C:42:12:34:56]]
So then, you could change your script to first check to see if that MAC exists in the table, and then proceed with doing whatever else. Something like:

ros code

:if ([:len [/interface wireless registration-table find where mac-address=$clientmac]] = 1) do={
  ... do stuff
} else={
  /log info "$clientmac MAC not found..."
}
 
User avatar
CyberTod
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Jan 25, 2012 10:23 am

Re: Get variable from registration-table problem

Tue Jan 07, 2014 6:53 pm

Thank you. I got the idea and put this solution in the script. Now it is working as intended.
But it is strange why it does that. This was not the case in previous versions. The command I posted returned a blank string.

Who is online

Users browsing this forum: Daguerdal and 19 guests