Automatic SOCKS Proxy for a Domestic IP Address

Update 2013-03-31: In Mac OS 10.8 (and maybe 10.7), the Airport name has been changed to Wi-Fi. The script should look like:

trap "{ networksetup -setsocksfirewallproxystate Wi-Fi off; }" INT
networksetup -setsocksfirewallproxy Wi-Fi localhost 3333
ssh -ND 3333 USERNAME@HOSTNAME

While enjoying a relaxing spring break in Jamaica, I was attempting to read through the monster that is Gödel, Escher, Bach: The Eternal Golden Braid. Hofstadter inspired me to check out the music of Bach, so I logged into my Rhapsody account. All good. But when I attempted to play the songs I received the message, “This content not available in your country.” That’s interesting, since I’m a US based subscriber to Rhapsody. The problem was that the request was coming from a Jamaican IP Address.

Of course, there is a way around this. SSH into a machine in the US and create a SOCKS proxy so that the web requests are coming from the US-based IP. But this was inconvenient to do every time I wanted to listen, so I made a shell script to automatically create the SSH connection, change my Mac’s system proxy to this, and undo all the changes when quit.

Running this script will require an SSH public key pair be created so that the remote machine can be connected to without a password. Edit the script to include the correct user and host names. This will only work on a Mac. It also assumes that you are getting internet through the Airport. If you are getting internet through ethernet change Airport on line 2 to Ethernet. Any suggestions on how to find which device is providing internet in the script to do this automatically?

trap "{ networksetup -setsocksfirewallproxystate Airport off; }" INT
networksetup -setsocksfirewallproxy Airport localhost 3333
ssh -ND 3333 USERNAME@HOSTNAME

This can be run directly from the command line, but I enclosed it in an Automator workflow so that I could launch it through LaunchBar as though it were an application. When the script is closed it should turn off the proxy and restore the previous IP.

I suspect this method should work for any site that restricts content by IP address. Netflix, Hulu and Youtube users will likely find this useful.

Advertisements

About Zachary Wasserman

Currently working on www.tenayaconsulting.com
This entry was posted in Shell Scripting and tagged , , , , , , , , . Bookmark the permalink.

One Response to Automatic SOCKS Proxy for a Domestic IP Address

  1. Solal says:

    Pretty impressive!
    We’re looking for an extra developer. If you’re looking for a job for the summer, I think we should talk 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s