Showing posts with label RouterOS. Show all posts
Showing posts with label RouterOS. Show all posts

Tuesday, January 6, 2009

Internode Scripts

Just finished some scripting work that allows me to mangle internode unmetered traffic for some of our office connections along with my home connection.

The file the IP's are grabbed from looks like this:



Case Studies:
1) Home - I have 2 ADSL Connections an 8mb (unlimited) AAPT link and a 12Mb (ADSL2+ 55gb) Internode link that I use to provide my family* I want to ensure all the free content always goes out over the internode link rather than the AAPT link as streaming abc iView etc loads faster over the Internode connection.I also use the internode linux mirror heavily to update my ubuntu boxes.

2) Work - We have a couple of seperate links along with a newly installed Internode ADSL2+ We also use a number of linux boxes here and would like to make best use of the free content.

I work with routers that run Mikrotik RouterOS. Have to say first up that despite a few small issues I've had with the software from time to time, it is in my opinion the best cost-to-value software I've ever used.

Compared to cisco products etc, I can purchase a mikrotik licence ($60AUD and up depending on the version) and choose my own hardware platfor. Eg: If I'm cheap i can use an old PC as a router, if I want reliability I can buy a RouterBoard system from $150AUD and up.

So anyway, onto the script itself.

Script name: Fetch-Node-IP-List

/tool fetch address=example.com host=example.com mode=http src-path=unmetered_ip_address_list.txt
:log info "Download Complete"
:delay 10
/system script run Add-Node-Unmetered-IPs


Due to the fetch command only supporting http, I've setup a cron job on one of the linux servers to download the internode list daily onto a server where I can access it via http. If people are interested in obtaining this list (via http) daily then I'll set it up on a box that is open to the general public.

The script above simply downloads the most recent list, waits 10 seconds for the download to be complete (just in case) and then triggers the list modification script. I also like to leave comments in the log so I can go back at any time and check the log to confirm the script completed each section sucessfully.

Script name: Add-Node-Unmetered-IPs

:log info "Begining Address List Modification"
:if ( [/file get [/file find name=unmetered_ip_address_list.txt] size] > 0 ) do={

/ip firewall address-list remove [/ip firewall address-list find list=Node-Unmetered]

:global content [/file get [/file find name=unmetered_ip_address_list.txt] contents] ;
:global contentLen [ :len $content ] ;

:global lineEnd 0;
:global line "";
:global lastEnd 0;

:do {
:set lineEnd [:find $content "\n" $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 1 ) ;

:if ( [:pick $line 0 1] != "\n" ) do={
:local entry [:pick $line 0 ($lineEnd) ]
:if ( [:len $entry ] > 0 ) do={
/ip firewall address-list add list=Node-Unmetered address=$entry
}
}
} while ($lineEnd < $contentLen) } :log info "IP List Modification Complete"


This script does the following:
1. Checks for the existance of a non-empty text file
2. If so (file with content exists) deletes the full current address list
1. Grab the txt file and places it's contents into a variable
2. Finds a full line and places it's contents into a second variable
3. Checks the line isn't blank
4. If so (the line isn't blank) adds the contents in as a new address list entry
5. If not(the line is blank) continue onto the next line
5. Repeat until the end of file

Future improvements:
In the short term this works fine for checking and updating a small list of addresses across a number of sites. In the real world I've done a couple of things a bit shabbily, such as removing the IP address list at 2am which means it will drop any open connections at this time (sure there may not be any people on now, but that isn't the case all the time).

I'll be looking at modifying this so the router checks current IP's vs the list and determines and modifies only additions or deletions from the active list. But not for now.

*By Family I mean, my parents house where the ADSL is connected, my house which is connected 4km away via wireless and my Uncle and Aunties place connected 1km via wireless. I pay for the Internode connection myself and don't charge any money for it. If I were making a living of this then a) I'd require a wireless carrier licence myself and b) I'd need to be paying for a SOHO or Business grade ADSL connection through internode.

Thursday, May 24, 2007

WRAP and RouterOS


As someone who is frequently involved in Hotspots, VPN's, QoS, Firewalling, Queuing and Shaping; I've chosen to use a WRAP 1-2 loaded up with RouterOS to manage my home connection.

The system had to support many features and preferably all in one package which the WRAP hardware makes easily possible (as opposed to my previous methods of piecing together discarded systems and old cards)

The setup comprises of an IPSEC Tunnel through to my work network, standard routes out through the ADSL Line (soon to be dual lines with load-balancing); Mikrotik Usermanager gives everyone a monthly limit on the ADSL connection.

Having the benefit of a mini PCI slot I can use my preferred wireless card (namely the SR2) and present an open wireless hotspot connection, meaning I don't have to worry about neighbors using my internet.

P2P shaping and simple Queueing means that web pages will always load quickly even if someone else is whipping their Bittorrent client. Even World of warcraft runs better ;-)

Best of all, I don't have to worry about noise, lack of space, excess power usage or hardware failure for years to come. The WRAP system has replaced 3 computers for me for less than the price of 1.

Some stats from the www.yawarra.com.au page:


WRAP 1-1 WRAP 1-2 WRAP 2 Indoor WRAP 2 Outdoor net4801
Features WRAP 1-1 WRAP 1-2 WRAP 2 Indoor WRAP 2 Outdoor net4801
Processor AMD Geode SC1100 - 233 MHz AMD Geode SC1100 - 233 MHz AMD Geode SC1100 - 233 MHz AMD Geode SC1100 - 233 MHz AMD Geode SC1100 - 266 MHz
Onboard memory 128MB 128MB 64MB or 128MB 64MB or 128MB 128MB or 256MB
Ethernet ports (10/100) 2 3 1 1 3
Throughput (MBits/sec) * 42.8 42.8 N/A N/A 33.6
mini-PCI slots 2 1 2 2 1
PCI slots None None None None 1
(3.3V cards only)
IDE interfaces 1 x CF type I/II 1 x CF type I/II 1 x CF type I/II 1 x CF type I/II 1 x CF type I/II
1 x 2.5" HDD
GPIO interface Yes Yes Yes Yes Yes
Serial ports 1 1 1 1 2
(1 internal, 1 external)
USB ports None
(1 or 2 port USB 1.1 expansion kit available)
None
(1 or 2 port USB 1.1 expansion kit available)
None None 1
(USB 1.1)
Power usage typical 3-5W @ 12V typical 3-5W @ 12V typical 3-5W @ 12V typical 3-5W @ 12V up to 15W (with HDD)
PPOE Yes Yes Yes Yes
(Recommended)
No
Network bootable (PXE) Yes # Yes # Yes # Yes # Yes
Case colours red, orange, green, blue, silver, black, white, yellow ^ red, orange, green, blue, silver, black, white, yellow ^ silver matt silver Soekris green, Yawarra black^
Size (mm) 163W x 161D x 28H 163W x 161D x 28H 110W x 166D x 28H 210W x 180D x 53H 216W x 157D x 35H
Weight (board & case) 420g 425g 378g 1718g 770g
C-Tick compliance Yes Yes Yes Yes Yes
Available products WRAP 1-1 board

WRAP 1-1
WRAP 1-2 board

WRAP 1-2
WRAP 2 board

WRAP 2 Indoor
WRAP 2 board

WRAP 2 Outdoor
net4801 board

net4801