I am back to outdo myself at presenting another pointless bash script
which has the potential to be a disgrace to the programming community. Maybe this will serve as documentation on how one can get carried away while writing code.
People who access the interwebs behind a proxy-server
will know the pain when things get slow and you have no clue which proxy-server
will work out and helplessly refer to the stars' alignment to choose a server. When KGP had one of its We bring you internet from the 90s moments, I had decided that there has got to be a way to choose a proxy based on the bandwidth all the proxies were offering. Either there isn't any popular service to do that or my googling skills need serious refinement. So I set out to implement a poor man's method of choosing an optimal proxy-server
from a multitude of choices and set that as the System-Wide Proxy
. The script is only for Linux
.
I have tested this on Ubuntu 14.04
(I know it's not the linuxest of OSes out there, but it rocks my boat). Identifying the optimal proxy-server
should work on any Linux distro. Setting the system proxy is specific to Ubuntu
.
I used curl
to download a test file (I chose a random file of 3MB. Replace the url based on your preferences - be sure to test that the download is working throught curl before using it) and got the request time. Choosing the minimum request time among the options, I selected the optimal server. I haven't got the faintest of ideas whether this is theoretically the optimal
server, but I guess it works for a naive implementation.
Let's call this proxychooser.sh
This gets the optimal proxy server.
I have toiled over an hour googling to find a generic method to set the System-Wide Http Proxy
on Linux
which doesn't involve a restart. Using the enivronment variable http_proxy
with export
doesn't work at all as it is restricted to that shell/session. Editing files like /etc/environment
didn't solve anything even when the network-manager
is restarted. So I had to go with the Ubuntu
specific approach, apologies to all the pure Linuxers out there if you feel let down.
A cool dude helped me on stackexchange regarding setting the System-Wide Proxy
on Ubuntu
. Add the following to the end of the above script proxychooser.sh
. I have got to admit that I don't fully understand how the following works, will have to dig into Ubuntu
's documentation sometime.
If you feel this is overkill, you can always manually set your proxy through GUI after getting the optimal server.
Save a file bus.sh
alongside proxychooser.sh
. I got this from stackexchange
Make sure both the scripts are executable by sudo chmod +x scriptname.sh
and run the proxychooser.sh
whenever you feel a need to change the proxy.
Here are the gists
for the working scripts. proxychooser.sh and bus.sh
I am counting on this post's popularity in KGP being minimal. A Game-Theoretic
analysis(or common sense) would deduce that the chosen optimal server might no longer be optimal
if the majority of the users opt for that server. Don't disappoint me junta. Be sure to expect some detailed posts on Game Theory in the future. Thanks.
Please point out any gaping mistakes or suggest anything that might improve the approach.
comments powered by Disqus