New application to split local and international traffic - now on Telkom Router

dawbomb

Well-Known Member
Joined
Nov 3, 2009
Messages
122
Hey all,

I've written a script to split traffic between local only and international connections on a Telkom duoPlus 300WR router. Works like a charm :)

I've also created a site to host such applications. Obviously my script is on there. If you've written a similar script for a different router, or a better script for the same one, please let me know! Contact details are on the site.

So far the current script on there only runs from linux, but its not too difficult to convert to a Windows script, I just haven't had the time.

If you're interested in using the script (free of course - I've made no attempt to hide the source code), check out http://sites.google.com/site/localrouter/.

Please post comments here or on the site
 

Quasimodo

Well-Known Member
Joined
May 16, 2009
Messages
114
From your web site:

"The aim of the Local Router project is to enable a router to enable a router to send traffic which is going to a local server through a local-only connection, and send all other bandwidth through another account."

"to enable a router" has been repeated twice.

Thanks for the link.
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,809
This is pretty much what the other guys are doing (Route Sentry and the new guy) for Windows. Except not as complicated (guess for Linux you need to be a bit complicated? However I'd recommend looking for some posts from TheRodent, think he ran several scripts or one script or something to split traffic between his ADSL and MyWireless accounts)

This should work on pretty much any router though btw... my opinion, I might be wrong
 

Pada

Executive Member
Joined
Feb 18, 2009
Messages
8,169
kilos, you can actually get cheaper local bandwidth than R7/GB from OpenWeb. When you take the 30GB for R131 then its about R4.4/GB

AcidRaZor, I don't see why the Linux scripts have to be more complicated. The only reason Gatecrasher's script is so complicated, is that it includes DDNS, mangling for multiple paths to the same news server, automatically updating the list of local routes, and a few other stuff.
I'm also running a traffic splitting script on my friend's Nanostation 5, and the script is VERY simple. Mine is simply lots of "route -add" lines in 1 script, which I've initially set up in notepad. Since the Nanostation supports SCP, you can simply copy the scripts with SCP to the it and then I just log in with telnet and execute the script. I haven't put in effort yet to save the script permanently on the router.

Unfortunately not all routers has a proper linux telnet/SSH interface, but I reckon that you could create a very simple script that should work on most routers. The fewer commands you use, the greater the chance of the script working on multiple routers would be.
Like Gatecrasher's script is using wget (to update the list) and my Nanostation doesn't have that. The Nanostation also doesn't support mangling :(
 

dawbomb

Well-Known Member
Joined
Nov 3, 2009
Messages
122
will that thing work on a planet router? ^^
In all honesty, I have no idea. I haven't tried, as I don't have access to one. Obviously setting up the second connection will be slightly different, but its worth a try. Just run the script. The worst that can happen is that you have to power off your router, and then power it on again.

According to your page
http://sites.google.com/site/localrouter/requirements you mention the cheapest local bandwidth is Axxess R10/Gb
but it is WebAfrica R7/Gb & OpenWeb R7/Gb
I wasn't aware of this. Thanks! I will add it shortly. I haven't had a chance to fiddle with the site recently I've just been really busy.

This is pretty much what the other guys are doing (Route Sentry and the new guy) for Windows. Except not as complicated (guess for Linux you need to be a bit complicated? However I'd recommend looking for some posts from TheRodent, think he ran several scripts or one script or something to split traffic between his ADSL and MyWireless accounts)

This should work on pretty much any router though btw... my opinion, I might be wrong
The script which you download spits out another script with the latest list of local IP addresses. So it may look complicated, but in essence it isn't really. I actually hadn't thought about that, it probably will work off all routers running a linux OS. Which is most of them.

All the expect line does in my script is force the shell to wait until the command has been completed before throwing out the next line, otherwise everything seems to get muddled.


kilos, you can actually get cheaper local bandwidth than R7/GB from OpenWeb. When you take the 30GB for R131 then its about R4.4/GB

AcidRaZor, I don't see why the Linux scripts have to be more complicated. The only reason Gatecrasher's script is so complicated, is that it includes DDNS, mangling for multiple paths to the same news server, automatically updating the list of local routes, and a few other stuff.
I'm also running a traffic splitting script on my friend's Nanostation 5, and the script is VERY simple. Mine is simply lots of "route -add" lines in 1 script, which I've initially set up in notepad. Since the Nanostation supports SCP, you can simply copy the scripts with SCP to the it and then I just log in with telnet and execute the script. I haven't put in effort yet to save the script permanently on the router.

Unfortunately not all routers has a proper linux telnet/SSH interface, but I reckon that you could create a very simple script that should work on most routers. The fewer commands you use, the greater the chance of the script working on multiple routers would be.
Like Gatecrasher's script is using wget (to update the list) and my Nanostation doesn't have that. The Nanostation also doesn't support mangling :(
As in my script, the only command which actually gets run on the router is "route".

Could I ask if people can run my script on their computers and just see if it works, and let me know the results? Thanks!
 

nihilist

Expert Member
Joined
Sep 8, 2005
Messages
4,521
dawbomb, nice work man :D

I might see about integrating this into improving on Bernie's script for IPCop which I've been using for ages now.

/me throws a beer your way :D
 

nihilist

Expert Member
Joined
Sep 8, 2005
Messages
4,521
Btw, your localroutes.txt is only about 600 lines long, this seems to be a bit lacking? Perhaps I'm wrong, but with my IPCop setup there are about 1600 routes, be careful you are not missing some, otherwise you might find traffic going over international aswell.
 

Pada

Executive Member
Joined
Feb 18, 2009
Messages
8,169
@nihilist:

Btw, your localroutes.txt is only about 600 lines long, this seems to be a bit lacking? Perhaps I'm wrong, but with my IPCop setup there are about 1600 routes, be careful you are not missing some, otherwise you might find traffic going over international aswell.
I haven't looked through dawbomb's localroutes.txt to see where he got it from, but I guess his 600+ routes would be suffice.

If you have 1600 routes for IPcop, it means that your routes aren't optimized (grouped together). Me and cenuij first noticed the same phenomenon with Gatecrasher's list of local IP's that he was using. It had like 1400+ entries, which we then managed to reduce to 700, without excluding or including hosts!

Now his script is simply downloading all the routes (already optimized) from http://developers.locality.co.za/routes.txt
See http://developers.locality.co.za/splitting for the other local lists that you can use if you feel that the 590 routes, compiled by Locality Developers, is not suffice. They update their lists every Wednesday.​

@Dawbomb,
I've modified your script to automatically download the latest list of local routes, change the localroutes.sh to executable and then executing the script.
You might want to check if "route add -net 41.0.0.0/11 ppp1" works on your router. I've tested this script with Ubuntu 9.10 and a Linksys WRT54GL with DD-WRT firmware on it.

Here's my modified version of your script:​
Code:
#!/bin/sh
#If your router's IP address is not 10.0.0.2, adjust the following line accordingly
host="10.0.0.2"

#If your router's login user is not root, adjust the following line accordingly
user="root"

#In the line below, replace <password> with your router login password:
passwd="<password>"

#If your router's local interface is not ppp1, adjust the following line accordingly
if="ppp1"

# Download new list of local routes
wget "http://developers.locality.co.za/routes.txt" -O localroutes.txt

modify()
{
	while read i s
	do
		if [ "$i" != "#" ]; then
			echo send \"route add -net $i $if \\\\r\" >> localrouter.sh
			echo expect \"# \" >> localrouter.sh
		fi
	done < localroutes.txt
}

echo "#!/usr/bin/expect --" > localrouter.sh

# Perform login
cat >> localrouter.sh << EOF

spawn telnet
expect "telnet>"
send "open $host\r"
expect "ogin: "
send "$user\r"
expect "word: "
send "$passwd\r"
EOF

# Add routes
modify

# Exit
cat >> localrouter.sh << EOF
send "exit\r"
send "!\r"
expect "$ "
EOF

# Make localrouter.sh executable
chmod a+x localrouter.sh

# Execute script
./localrouter.sh
 

dawbomb

Well-Known Member
Joined
Nov 3, 2009
Messages
122
You might want to check if "route add -net 41.0.0.0/11 ppp1" works on your router. I've tested this script with Ubuntu 9.10 and a Linksys WRT54GL with DD-WRT firmware on it.
I tried, but it doesn't :( I'm using a Telkom duoplus 300WR. It spits out
Code:
route: can't resolve 41.0.0.0/11
Here's my modified version of your script:
Awesome! Thanks! I like what you've done! I wanted it to do that in the beginning, except, er, my bash knowledge (or lack of it rather) doesn't allow it!

In order to solve the issue with it not liking the 41.0.0.0/11 format, you can replace the http://developers.locality.co.za/routes.txt line with http://ip.ludost.net/cgi/process?country=1&country_list=za&special_Local=on&format_template=mask&format_name=&format_target=&format_default=. That then gets the list with subnets, which my router can understand. But thats not compatible with your code, and I'm too tired to change it. I'll change that in the morning, and then upload it.

Is your router ok with the 41.0.0.0 255.224.0.0 format? If it isn't, then we can just have two different files...

Thanks so much for helping!
 

dawbomb

Well-Known Member
Joined
Nov 3, 2009
Messages
122
dawbomb, nice work man :D

I might see about integrating this into improving on Bernie's script for IPCop which I've been using for ages now.

/me throws a beer your way :D
Shot mate! I haven't had a good look at ipcop yet, but I will do in the morning. I'll also add a link pointing towards ipcop to my site. And a few other projects like ipcop. The idea is that people can go to my site, check their router, and off they go from there. Thats the idea of course, time dependant...
 

dawbomb

Well-Known Member
Joined
Nov 3, 2009
Messages
122
I'm still waiting for google to index my site, so that it can be searched for in google. Honestly, how long can it take to index a site thats on their own servers!
 

Pada

Executive Member
Joined
Feb 18, 2009
Messages
8,169
Replace just the following section if your router cannot use the CIDR format:

Code:
# Download new list of local routes
wget "http://developers.locality.co.za/routes-rs.txt" -O localroutes.txt

modify()
{
	while read i s
	do
		if [ "$i" != "#" ]; then
			echo send \"route add -net `echo $i | sed 's/,/ netmask /'` $if \\\\r\" >> localrouter.sh
			echo expect \"# \" >> localrouter.sh
		fi
	done < localroutes.txt
}
 

dawbomb

Well-Known Member
Joined
Nov 3, 2009
Messages
122
Epic, shot! Works like a charm! I'll update the site accordingly asap.

Those two scrips should cover almost all routers... I think? Correct me if I'm wrong.
 

Pada

Executive Member
Joined
Feb 18, 2009
Messages
8,169
dawbomb, the only thing that we might improve in the script would be to automatically install the "expect" package, but I reckon thats not worth it.

I would reckon that the one script would work on basically all routers. Btw, don't you now have just 1 script? OR did you publish a different one for using another local list?
 

kilos

Expert Member
Joined
Jun 28, 2005
Messages
2,737
kilos, you can actually get cheaper local bandwidth than R7/GB from OpenWeb. When you take the 30GB for R131 then its about R4.4/GB
Thanks Pada - thats true I never did the sums

Like Gatecrasher's script is using wget (to update the list) and my Nanostation doesn't have that. The Nanostation also doesn't support mangling :
Maybe Pada - you can use static routes in the Nanostation - see the Ubiquiti Wiki
http://www.ubnt.com/wiki/index.php/Manual_Routes
 
Last edited:

dawbomb

Well-Known Member
Joined
Nov 3, 2009
Messages
122
dawbomb, the only thing that we might improve in the script would be to automatically install the "expect" package, but I reckon thats not worth it.

I would reckon that the one script would work on basically all routers. Btw, don't you now have just 1 script? OR did you publish a different one for using another local list?
If the expect package gets installed automatically, then the script has to be run as root. The script doesn't actually have to be run as root, so from a security point of view its probably better if we just leave it as is.

I published 2 scripts. One of them uses the format your router likes (version 1), and the other uses the format that my router likes. Does your router accept routes in the form IP netmask? I'm going to clarify the instructions now...

The other thing I'd like to do is to get it to run on Windows too. Its definately doable... I just need to work out the syntax changes.

Expect for windows
 

Pada

Executive Member
Joined
Feb 18, 2009
Messages
8,169
Yes, my router accepts both methods: subnet masks or CIDR format.

I think you can assume that every single router would accept it in subnet mask form.
 
Top