Script to set gw for bunch of IPs?

Hello. First of all, this is my first script.
Second… well, some of you may heard about “russian firewall” which is used by gov to block sites that considered harmful. Main problem is that it blocks sites by IP and not URL, for example we have 2 of 6 IPs of wordpress.com blocked right now. Obviously this causing problems.
So i decided to write simple script which will download list of blocked IPs, add them to route table and set their gw to my VPN server.
And here is first problem…

/tool fetch url=http://api.antizapret.info/group.php dst-path=crapregistry.txt
/file edit value-name=contents crapregistry.txt

Uh… file is empty!

/tool fetch url=http://api.antizapret.info/group.php dst-path=crapregistry.txt
:global test [/file get crapregistry.txt contents];
:put [$test];

Uh… empty response!

And here is whole script, but since i’m unable to get file to read i can’t test it… Maybe you can suggest me how i can optimize it, maybe there is very idiotic errors, maybe something else. Yeah, i know it filled with “bad syntax” comments, but this is just for better understanding.
#set this variable to your VPN interface name
:global vpn-iface “ovpn-somewhere”;
#and this to list of blocked IP addresses
:global ip-list “http://api.antizapret.info/group.php
#and this to preferred comment for added routes
:global route-comment “#CRP
#actual script
tool fetch url=$ip-list dst-path=crapregistry.txt
#this is for parsing lines in file. Stole it from wiki
:global content [/file get [/file find name=test.txt] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line “”;
:global lastEnd 0;

#remove all previously added routes before refresh. Maybe i can compare lines instead of removing them all?
/ip route remove [find comment=$route-comment]

#loop for adding new IPs
:do {
:set lineEnd [:find $content “\r\n” $lastEnd ] ; #should verify line endings from that file
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 2 ) ;

   :put $line; #this is just for debug. Should print single IP

#/ip route add dst-address=$line gateway=vpn-iface comment=$route-comment
} while ($lineEnd < $contentLen)

There is a 4096 byte read/write limit on files. I downloaded the file and it was 4575 bytes.

(MikroTik, we need a bigger limit :slight_smile: Will this ever be increased?)

There are other ways to get it done. Maybe this post would be helpful: http://forum.mikrotik.com/t/how-to-automatically-synchronize-ips-from-malcode-com/64111/1