Problem with script - works only 3 times :/

I wrote a script to block users depending on thier last-ip (do not ask why)

The script works fine, but after 2-3 runs script don’t want to add mac addresses do the accesslist anymore. why? where there may be an error?

:global rcount
:set rcount [:tonum [/interface wireless registration-table print count-only ]];
:for i from=0 to=$rcount do={ 
    :local lastip [/interface wireless registration-table get $i last-ip ]
		:if ($lastip = "168.155.112.56") do={
		:local macaddres [/interface wireless registration-table get $i mac-address]
		/interface wireless access-list add authentication=no comment=_auto_remove mac-address=$macaddres
		
		}
}

As to why it is having an issue running, I don’t know, but I would suspect the issue is with this line: “:if ($lastip = “168.155.112.56”) do={”, I’m taking a shot in the dark that either it’s seeing $lastip as a string and the IP address as an address, or the other way around. Try converting lastip to a string or to an ip address and see what happens.

i did it :slight_smile:

{
:foreach i in [/interface wireless registration-table find interface=wlan1] do={ 
 :local lastip [/interface wireless registration-table get $i last-ip]
		:if ($lastip = "168.155.112.56") do={
		:local macaddres [/interface wireless registration-table get $i mac-address]
		/interface wireless access-list add authentication=no comment=_auto_remove mac-address=$macaddres
		:log error "I blocked this MAC: $macaddres"
		}
}
}

it seems like the for loop

:for i from=0 to=$rcount do={

wasn’t right here. Now it’s ok.