Disable items from the address list with a .txt file

Hi mikrotikers,

I am trying to disable items from the address list by reading a .txt file inserted into files, but when I run the script it prompts the number of the item that I want to disable and also an error “interrupted no such item”…in other words…not working at all

This is the script

:global filetext [/file get disable.txt contents];
:global filepos 0;

:global numbers;
:local linend;
:local :thisline;

:while ($filepos < ([:len $filetext]-1)) do={
	:set linend [:find $filetext "\n" $filepos];
	:set thisline [:pick $filetext $filepos $linend];
	:set numbers [:pick $thisline 0 $linend];

	:put $numbers;
	:set filepos ($linend+1);
	/ip firewall address-list disable "$numbers";
}

could you guys give me a hand with this? I am trying to disable some items automatically, something to work like this

/ip firewall address-list disable 0;
/ip firewall address-list disable 3;
/ip firewall address-list disable 8;

Thanks in advance for your support! :smiley: :smiley:

by the way…the “disable.txt” file would look like this

0
3
5
6

Make sure this line doesn’t have the colon before “thisline”:
:local thisline;And, insert this line before the /ip firewall disable line:
/ip firewall address-list printA downside to using this method is that it generates the “numbers” based on the order the address-list entries were created, so if you delete / add / etc, the order will be different. A better way is to disable rules based on the IP or comment, which makes the script more flexible. For example, if you wanted to disable a particular IP:
/ip firewall address-list disable [find address=“192.168.1.5”]Then, regardless of the “number” of that address-list entry, it will always disable the correct one.

One other thing to keep in mind is that your txt file needs to have a new line after the last number, or it will be skipped.

Hi Skot,

Thanks a lot for the hint

/ip firewall address-list disable [find address="192.168.1.5"]

I changed it a little bit but it worked out fine finally…If I could have the option of giving you karma I would buddy…Thanks!