Not sure if this is a one-time need or maybe you are seeking for a way to automate this; if it needs to be the script way, check for the CSV having suitable end of line characters, where is it failing?
If this is a one time need: a hack or workaround without resorting to scripting would be opening that csv file on a text editor then using find/replace to put
/ip firewall address-list add address=
by searching for the beggining of line, so that text is placed before the IP, and then
Both by the way have plugins for ROS syntax coloring.
The idea is to end with the CLI commands on the text file; that way you can rename it to .rsc, upload it to the router then do an import on the .rsc.
Following this idea, and as you may be reaching maximum file size for file processing using scripting, you could also generate the .rsc file containing all the CLI to fill the list by coding an smal cgi in bash or php, then just fetching the file from your web server…
hi, yes that script from the wiki is old and does not work on 6.x , however if you make changes to the do / while loop, it will work (move the :while up), change it like this:
:while ($lineEnd < $contentLen) do={
:set lineEnd [:find $content "\n" $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 1 ) ;
#If the line doesn't start with a hash then process and add to the list
:if ( [:pick $line 0 1] != "#" ) do={
:local entry [:pick $line 0 $lineEnd ]
:if ( [:len $entry ] > 0 ) do={
/ip firewall address-list add list="MY-IP-LIST"
}
}
}
}
Anyone that can help me out why this does not work ?
Basically I combined some posting in order to make a script that should work, but it only cleans/empties my "DNS" address-list.
I've download the link below containing a bunch of DOH/DOT public servers that I want to convert into an ACL.
Basically I took the (non-working on RouterOS 6.x) script from the WIKI and added the correction that is suggested to make it work again in this post.
But still, list remains empty basically.
The "iplist.txt" contains some line starting with # which should be ignored.
It also contains some "blank" lines, I wonder if that is ok.
Below a small piece of the list.
DNS over HTTPS (DoH) server IP list
This is a list of IPs which correspond to publicly available DoH providers
It can be used to firewall these IP addresses
This list was generated by running dig +short HOSTNAME A
List is only 5Kb big, but the script does not work, just throws an error in the log as the script is instructed to do.
Looking at the original script, the "list" that mostly resembled the one I try to import is the one below
The URL I'm using contains some blank lines too, but I would think the script (looking at the regex) really looks for dotted IP constructs and ignored everything else, including "#" characters etc
And before starting the script i do have a list called "DNS" and it does not remove it, even when I change the script slightly like
ip firewall address-list
:local update do={
:do {
:local data ([:tool fetch url=$url output=user as-value]->"data")
remove [find list=DNS]
I would expect it to simply deleted list "DNS" but it remains in place.
Of course for this particular purpose you could also make a DNS-based address list. Either using the DNS names from that list or by hosting some domain and loading it with the proper addresses for some name like doh-servers.example.com
I have tested it with this version and it works. Run it in terminal and see if it works. If it does not work in script then you have to set the rights. (ftp, read, write, policy, test, password) It could be to much rights but it works for me.
It is a really nice bit of code and very sturdy so assumed it work also for this and it does? As long the files are not longer then 63KB this is just the code to use.
This will only accept IP addresses that are at the beginning of the line(RegEx):
This list probably is not so “dynamic” compared to others. So 1 update per day (or even per week) should be OK.
I’m going to check IF there are some hits against the counters anyway.
Unfortunately RouterOS does not support counters per address list entry. Plain Linux does, at least in the current version (the first version of “ipset” did not support that).
It would be nice when RouterOS address list had these counters, so you can see how active such entries are. Now you can only count per firewall rule, i.e. for all list items together.