block static ip script failure in version 4.5

This script works fine in version 2.9.11 , but is not working in version 3.2 and 4.5.Any help please?What we need to do?


\

find static IP version 8

:log info (“!!! SYS UPTIME (-” . [/ip address get [/ip address find interface=wlan1] address] . "-) → " . [/system resource get uptime]);

:set countusers 0;
:foreach k in [/ip arp find interface=ether1] do={:set countusers ($countusers + 1); /ip arp remove $k;}
:log info ("!!! USERS ONLINE → " . $countusers);
:delay(60);

:foreach i in [/ip arp find interface=ether1] do={

:set arpip [/ip arp get $i address];
:set arpmac [/ip arp get $i mac-address];

:set notstatic 0;


:foreach j in [/ip dhcp-server lease find] do={

:set dhcpip [/ip dhcp-server lease get $j address];

:if ( ($dhcpip=$arpip) ) do={:set notstatic ($notstatic +1);}

list of acceptable ip. Separate with ||

:if ( $arpip=10.207.100.1 || $arpip=10.207.1.1 || $arpip=10.207.1.2 || $arpip=10.207.1.3 || $arpip=10.207.1.7 || $arpip=10.207.100.2 || $arpip=10.207.100.3 || $arpip=10.207.100.4 || $arpip=10.207.100.5 || $arpip=10.207.100.7) do={:set notstatic ($notstatic +1);}

}

:if ($notstatic =0) do {
:log info (“!!! STATIC IP → " . $arpip . " mac " . $arpmac . " waiting 100 seconds to confirm.”);
:delay(100);
:set notstatic 0;
:foreach j in [/ip dhcp-server lease find] do={

:set dhcpip [/ip dhcp-server lease get $j address];

:if ( ($dhcpip=$arpip) ) do={:set notstatic ($notstatic +1);}

list of acceptable ip. Separate with ||

:if ( $arpip=10.207.100.1 || $arpip=10.207.1.1 || $arpip=10.207.1.2 || $arpip=10.207.1.3 || $arpip=10.207.1.7 || $arpip=10.207.100.2 || $arpip=10.207.100.3 || $arpip=10.207.100.4 || $arpip=10.207.100.5 || $arpip=10.207.100.7) do={:set notstatic ($notstatic +1);}

}
}
:set isinfirewall 0;

:if ($notstatic =0) do {
:log info ("!!! STATIC IP → " . $arpip . " mac " . $arpmac );

:foreach m in [/ip firewall filter find comment=("Blocked Mac " . $arpmac . " of Static IP " . $arpip)] do={:set isinfirewall 1};

:if ($isinfirewall =0) do={
/ip firewall filter add chain=forward src-mac-address=$arpmac action=drop comment=(“Blocked Mac " . $arpmac . " of Static IP " . $arpip);
:log info (”!!! STATIC IP → " . $arpip . " mac " . $arpmac . " → BLOCKED");
} else={
:log info (“!!! STATIC IP → " . $arpip . " mac " . $arpmac . " → Already Blocked”);
};

}

}

These need to be changed from set to local.

:set countusers 0;
:set arpip [/ip arp get $i address];
:set arpmac [/ip arp get $i mac-address];
:set notstatic 0;
:set dhcpip [/ip dhcp-server lease get $j address];

Like this:

:local countusers 0;
:local arpip [/ip arp get $i address];
:local arpmac [/ip arp get $i mac-address];
:local notstatic 0;
:local dhcpip [/ip dhcp-server lease get $j address];

I did not check the rest of the script. See if that helps.

Thanks SurferTim
but nothing happen :frowning: :frowning: :frowning:

anybody HELPPPP

Also, put a space between :delay and ();
Ex.

:delay (60);

Where are you editing these commands? If you are using V3.x or V4.x and using the CLI script editor, haven’t you noticed the colors? Everything correct will be in color (green, magenta, etc). The script turns to black and white at an error. Makes it really easy.

/system script
edit myscript source

Change one error, then Ctrl-o to save, and re-open the editor
edit myscript source
(ADD: Or if you are as lazy as I am, up arrow - enter)

Work your way down until all the white text is gone! :smiley:

“F5” will refresh the editor, so you can skip saving/opening again and do that only when you are actually finished.