Script to assign ip ranges in text file to address list.

Hi

I seem to have a bit of a problem. I would like to import a large list of IP ranges into an address list, but the list of ip ranges are stored in a text file and are separated by a return character (enter). I have attached the list for reference. Is it possible to script something that can move through this list and store each entry in a variable temporarily, then assign that variable to the desired address list and then move on to the next entry in the file.

I have little experience with using files in MT-scripts and don’t seem to find a method that I can distinguish between the contents within that file. It would have been quite simple if all the entries where a fixed length, say xxx.xxx.xxx.xxx, but unfortunately there are some entries that are xx.xx.xx.xx (for instance), thus using a ‘find’ and ‘pick’ approach would prove difficult.

Any help will be much appreciated.

Thanks.
sadc-routes.txt (17.2 KB)

A script for this is on the wiki:
http://wiki.mikrotik.com/wiki/Using_Fetch_and_Scripting_to_add_IP_Address_Lists

However, it does not work with your IP list because the file size is 17500 bytes. Currently there is a file read/write size limit of 4K (4096 bytes):
http://forum.mikrotik.com/t/save-export-to-variable/36882/3

I deleted a bunch of lines in your text file (getting the file down to less than 4096 bytes), and then tried the script. I tested this in RouterOS 5.7, and I had to fix the comment line that says: “#If the line doesn’t start with a hash then process and add to the list”. It was causing errors, so I just deleted it, and then the script worked fine.

One problem I noticed with the script is that if the last IP address in the text file will not be read unless “\n” (a new line) has been detected. So, if there is not a new blank line at the end of the text file, you’ll be missing the last IP address.

If you can break up the IP list and send it in parts, you should be set.