Use proxy only on one network

Joshua Root jmr at macports.org
Wed Aug 20 10:28:59 PDT 2014


> I'm experimenting with running a proxy server on my network, which I would like MacPorts to use while on that network, while not interfering with my ability to use MacPorts while connected to other networks. What's the best way to do this in an automated way? Editing macports.conf proxy settings every time I switch networks is cumbersome. Similarly manually setting and unsetting environment variables. I'm currently thinking of wrapping the "port" command in a shell function (which I already do) and using the IP address or AirPort network name to determine whether I'm on the home network and setting the environment variables accordingly. I'm also dimly aware of OS X's network locations feature, but way back when those were introduced I remember you had to manually select which location you wanted to use.

This is what I have on my laptop:

LOCATION=$(scselect 2>&1 | grep "^ \*" | cut -f 2)
case "$LOCATION" in
"(Home)")
        unset http_proxy
        unset FTP_PROXY
        ;;
"(Work)")
        export http_proxy="http://workproxy:3128"
        export FTP_PROXY="http://workproxy:3128"
        ;;
*)
        echo unknown location $LOCATION
        ;;
esac

There are apps that will switch locations for you automatically based on
AirPort SSID or other network characteristics. Alternatively you could
look at the output of something like 'networksetup -getairportnetwork
en1' instead of the scselect command used above .

- Josh


More information about the macports-users mailing list