Community discussions

MikroTik App
 
jperep
just joined
Topic Author
Posts: 1
Joined: Wed Dec 30, 2020 10:06 am

Add IP to list address from file

Wed Dec 30, 2020 11:44 am

Within a file ipaddress.txt there is a list of IPs, each on a line. The idea is to run the script and have it add them to a blocking address list. When I run the script I get the following error "is not a valid dns name".

ipaddress.txt example:
192.168.23.1
195.53.123.19
207.143.214.26

Script:

:if ( [/file get [/file find name=ipaddress.txt] size] > 0 ) do={
# Remove exisiting addresses from the current Address list
/ip firewall address-list remove [/ip firewall address-list find list=MY-IP-LIST]}

:global content [/file get [/file find name=ipaddress.txt] contents] ;
:global contentLen [ :len $content ] ;

:global lineEnd 0;
:global line "";
:global lastEnd 0;

:while ($lineEnd < $contentLen) do={
:set lineEnd [:find $content "\n" $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 1 ) ;
:local entry [:pick $line 0 $lineEnd ]
:if ( [:len $entry ] > 0 ) do={
/ip firewall address-list add list="MY-IP-LIST" address=$entry
}
}

I can't find the problem, if anyone can help me with this I appreciate it
Thank you!
 
ronaldviscarra
just joined
Posts: 1
Joined: Thu May 20, 2021 6:12 pm

Re: Add IP to list address from file

Thu May 20, 2021 6:18 pm

Hi, late but for some one else facing the same issue, I made it works by only keeping the lines wih IP, no blank lines neither starting with #, and change the end of line to UNIX style too.
Remove every space at the end and start of the line with IP.
Add at the last line one more new line character.

All in the ipaddresst.txt file

With theese changes works fine.
Last edited by ronaldviscarra on Thu May 20, 2021 6:19 pm, edited 1 time in total.

Who is online

Users browsing this forum: No registered users and 17 guests