Community discussions

MUM Europe 2020
 
nbctcp
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Tue Sep 16, 2014 7:32 pm

Script to convert ip to address-list

Thu Mar 03, 2016 1:49 pm

Hi,

Let say I have 7k ips in this text
http://torstatus.blutmagie.de/ip_list_a ... st_ALL.csv

I want to convert all those ips into address list using script
something like this
:do {/ip firewall address-list add address=$entry list=list-TOR}

I am following this method but the script can't create MY-IP-LIST address list
http://wiki.mikrotik.com/wiki/Using_Fet ... ress_Lists

Anyone have working script with RouterOS 6.34.2

tq
 
User avatar
pukkita
Trainer
Trainer
Posts: 2986
Joined: Wed Dec 04, 2013 11:09 am
Location: Spain

Re: Script to convert ip to address-list

Thu Mar 03, 2016 6:05 pm

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

list=YOURLIST

by searching for end of line.

Another way would be by using a text editor with block or column mode editing capabilities, like SublimeText or notepad++ for example (see https://notepad-plus-plus.org/features/ ... iting.html).

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...
Simplicity is the Ultimate Sophistication - Da Vinci
Getting the most out of this forum
 
nbctcp
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Tue Sep 16, 2014 7:32 pm

Re: Script to convert ip to address-list

Sat Mar 05, 2016 1:30 am

I am trying to avoid to use other server to process it.
It can be done by following this method
http://robert.penz.name/983/filter-traf ... -routeros/
I prefer everything using buil-in script in Mikrotik
I think if older RouterOS can do that, newer one will be more capable doing that
 
jo2jo
Forum Veteran
Forum Veteran
Posts: 959
Joined: Fri May 26, 2006 1:25 am

Re: Script to convert ip to address-list

Sun Dec 01, 2019 1:15 am

Hi,

Let say I have 7k ips in this text
http://torstatus.blutmagie.de/ip_list_a ... st_ALL.csv

I want to convert all those ips into address list using script
something like this
:do {/ip firewall address-list add address=$entry list=list-TOR}

I am following this method but the script can't create MY-IP-LIST address list
http://wiki.mikrotik.com/wiki/Using_Fet ... ress_Lists

Anyone have working script with RouterOS 6.34.2

tq

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"
            }
          }
       }
       }
:beep :beep :beep

Who is online

Users browsing this forum: No registered users and 5 guests