HTTP Proxy for Netflix, Hulu or other services for OS X

In this blog entry you’ll learn how to set up your own proxy into the USA so that you can easily view the same things that americans do. The post explains the bare minimum to get started for free.

Prerequisites

  • An OS X installation - set up yourself
  • A DigitalOcean account – with this link you start out with $10 USD to play with. You’ll need to confirm your e-mail.
  • Homebrew - see below

1. Newbie - start here - installing homebrew

You need to open something called the Terminal. Press Cmd+Space to see Spotlight, and write ‘Terminal’, press Enter. Now you can install homebrew by pasting the following into the terminal and pressing Enter:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

It will take a few seconds, and then you can install almost any program using the Terminal. We’ll start by installing jq, which is a JSON parser (a thing that can help your computer talk with DigitalOcean).

When it asks for your password, it’s the password for your computer, not DigitalOcean.

If you want to ever ‘retry’ something in Terminal, just press up arrow and run the command again.

2. Installing jq

In the same Terminal that you have open, run (paste + Enter):

brew install jq

3. Setting up DigitalOcean

  1. Go to DigitalOcean and sign up.
  2. Go to cloud.digitalocean.com/settings/applications and generate yourself an API write token, which you’ll use below.

Create a read-write token

Take the API key and run this in your Terminal:

export DIGITALOCEAN_TOKEN="YOUR API KEY HERE"

replacing the text YOUR API KEY HERE with your API key.

4. Setting up SSH - the tunnel software

Still in your terminal, replace email@example.com with your own e-mail and press Enter to all the questions asked by:

ssh-keygen -t rsa -C email@example.com -f ~/.ssh/digitalocean

You can use the same “passphrase” as your digital ocean account, or you can just press ENTER to set an empty pass phrase. This is the ‘key’ you’ll unlock your new computer with.

Now you have a key for the tunnel. We have to let DigitalOcean know of this key, so that you can use the tunnel script:

KEY=$(ruby -e "require 'json'; puts ({ :name => 'digitalocean', :public_key => File.readlines('$HOME/.ssh/digitalocean.pub')[0].chomp }).to_json") && \
  export SSH_KEY_ID=$( \
    curl -X POST \
         -H 'Content-Type: application/json' \
         -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
         -d "$KEY" "https://api.digitalocean.com/v2/account/keys" \
    | jq '.ssh_key.id')

The first part formats the key for the API, the second part (starting with export ...) calls the API and gets the key id from it.

With this command, DigitalOcean knows about your key, and you can use the actual script to create the tunnel - start by downloading the script:

curl -L -o digitalocean-proxy https://gist.githubusercontent.com/haf/7d80fc4527d4733aef0c/raw/digitalocean-proxy.sh

Now, make it executable:

chmod +x digitalocean-proxy

5. Starting the tunnel

Again in your Terminal, write:

./digitalocean-proxy

This will take about a minute or two to set up the proxy from scratch. When you’re done with it, you can press CTRL+C to stop it and it will be fully torn down and the data inside the proxy scrubbed.

You can navigate to http://www.ip-address.org/ and scroll down to see where you browser belives you are physically.

Now that you’re “in the states” you can might have some ideas about what online services that could entertain you.

Conclusion

If you liked this post and are new to either the Terminal or haven’t seen some of the commands used here, before, but thought it was cool that you can make computers do things like this, I recommend checking out Coursera - Learn to Program: The Fundamentals which goes through the basics.

As you progress in your knowledge, you’ll find that a world of possibilities opens up - programming is indeed the literacy of the 21’st century. If you have questions, you can find my e-mail at github.com ;).

Post Scriptum - make it work the next Terminal session too

Run this:

echo "export SSH_KEY_ID=$SSH_KEY_ID" >>~/.bash_profile

And then:

echo "export DIGITALOCEAN_TOKEN=$DIGITALOCEAN_TOKEN" >>~/.bash_profile

Voila!

Twitter @henrikfeldt

Twitter @logarylib

Henrik Feldt +46 737 53 27 18 haf