Community discussions

MikroTik App
 
1littlewisp
newbie
Topic Author
Posts: 36
Joined: Wed Jun 10, 2009 6:23 pm

`cat` equivalent for scripting / for loop / exclude comments

Sun May 20, 2012 5:12 am

Hello, all!

Found this awesome list of up-to-date bogon IPs.

http://www.team-cymru.org/Services/Bogo ... s-ipv4.txt

I'm grabbing the current version nightly. The idea is to iterate through the entries in this list and add them to an address list to be blocked on the WAN interface. There are two hurdles preventing me from doing so, and I'm sure they're limitations of my knowledge, not of mikrotik.

1) Can't seem to find any sort of `cat` equivalent to manipulate data within files stored on-disk.

2) Can't figure out how to properly exclude lines beginning in "#".

Any insight on this is appreciated.
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: `cat` equivalent for scripting / for loop / exclude comm

Fri May 25, 2012 1:04 am

File handling in RouterOS is very basic, no cat-like commands. Aside from that, the file is 80+KB. That is a problem because inside RouterOS there is a 4KB limit for reading / writing files: http://forum.mikrotik.com/viewtopic.php ... 42#p203311

I would do something like this: Download the file locally to PC, use other software to remove the # lines and add correct code, basically make the file into a script. So this:
# last updated 1337878082 (Thu May 24 16:48:02 2012 GMT)
0.0.0.0/8
5.10.0.0/18
223.130.28.0/22
224.0.0.0/3
# eof
would become:
/ip firewall address-list
add address=0.0.0.0/8 list=BlockedList;
add address=5.10.0.0/18 list=BlockedList;
add address=223.130.28.0/22 list=BlockedList;
add address=224.0.0.0/3 list=BlockedList;
Name the new file something.auto.rsc, upload to the router using ftp, and the script will execute automatically. Of course, if the ip already exists, a duplicate will be added, so checking for that would also need to be added to the script.