Sunday, March 28, 2010

turning proxies on and off easily

Proxies for MacOS X are to be configured in the network preferences, individually for each network interface. Sometimes, that's not what you want, and Authoxy or FoxyProxy can be great tools. FoxyProxy in particular lets you switch between different proxies for Firefox, and also lets you turn them on and off easily or even automatically by certain URL patterns. Wouldn't it be great to do similar things also for other programs, or, say Safari? Using a little scripting, that's indeed quite simple. For me, it is sufficient to turn on and off a proxy located in another country, allowing me to view certain online TV using Safari. But you could do more. The magic ingredient is
networksetup
a command line tool to the network preference pane. Just look at the manpage for a list of available options. And here's my little script to turn on and off the proxy services, especially the streaming proxy is important for me, so that I don't have to use the mouse to do that:
#!/bin/bash
# Copyright (C) 2010 by Bjoern Rueffer

usage() {     cat <<EOF
usage: proxy Airport|Ethernet on|off

This will switch all proxies (http,https,rtps) on/off for the named interface.
EOF
exit 1
}

if [ $# -ne 2 ]; then
 usage
fi
if ([ $1 != Airport ] && [ $1 != Ethernet ]) || \
([ $2 != on ] && [ $2 != off ]); then
usage
fi

sudo networksetup -setwebproxystate $1 $2;
sudo networksetup -setsecurewebproxystate $1 $2;
sudo networksetup -setstreamingproxystate $1 $2;     

0 comments:

Post a Comment

Comments are moderated to prevent abuse and may not be made public immediately.


Björn Rüffer, Copyright 20092011
Disclaimer: The author of this page cannot accept any responsibility for content of pages that this page provides hyperlinks to. Also the author cannot accept responsibility or liability for any damage caused by following or not following instructions given on this page. This page, its contents and style, are the responsibility of the author and do not represent the views, policies or opinions of any other party. The author will not be held responsible for comments posted by third parties on this site. Inappropriate comments will be removed. There is no warranty for any program or source code provided here, to the extent permitted by applicable law. Except when otherwise stated in writing the copyright holders and/or other parties provide the program “as is” without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program is with you. Should the program prove defective, you assume the cost of all necessary servicing, repair or correction.