Community discussions

MikroTik App
 
andrescamino
Member Candidate
Member Candidate
Topic Author
Posts: 198
Joined: Wed Aug 19, 2009 7:07 pm
Location: Guayaquil-Ecuador

Disable items from the address list with a .txt file

Tue Oct 15, 2013 5:09 am

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! :D :D
 
andrescamino
Member Candidate
Member Candidate
Topic Author
Posts: 198
Joined: Wed Aug 19, 2009 7:07 pm
Location: Guayaquil-Ecuador

Re: Disable items from the address list with a .txt file

Tue Oct 15, 2013 5:27 am

by the way...the "disable.txt" file would look like this

0
3
5
6
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Disable items from the address list with a .txt file

Tue Oct 15, 2013 7:47 am

Make sure this line doesn't have the colon before "thisline":

ros code

:local thisline;
And, insert this line before the /ip firewall disable line:

ros code

/ip firewall address-list print
A 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:

ros code

/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.
 
andrescamino
Member Candidate
Member Candidate
Topic Author
Posts: 198
Joined: Wed Aug 19, 2009 7:07 pm
Location: Guayaquil-Ecuador

Re: Disable items from the address list with a .txt file

Sun Oct 27, 2013 7:30 pm

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!

Who is online

Users browsing this forum: No registered users and 13 guests