Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xxuejie/188f2fa84ac6958c592c64428637a06c to your computer and use it in GitHub Desktop.
Save xxuejie/188f2fa84ac6958c592c64428637a06c to your computer and use it in GitHub Desktop.
How to connect an iOS device to your computer via a SOCKS proxy. Say you're running a virtual machine on your work computer. Say this machine, for whatever reason, can only connect to the internet over NAT - as in, it does not get it's own IP address. Say this VM is running a webserver, and you need a device outside of your computer to connect t…

How to connect an iOS device to your computer via a SOCKS proxy

Say you're running a virtual machine on your work computer. Say this machine, for whatever reason, can only connect to the internet over NAT - as in, it does not get it's own IP address. Say this VM is running a webserver, and you need a device outside of your computer to connect to it.

If only there was a way to get your work computer to 'share' it's network, so that you could get at that VM… Here's how you do it!

For all instructions, I assume your work computer is a mac

  1. Get your computer's IP address:

    ifconfig

    Note you need to find the local IP in your wifi network, typical values for this type of IP look like 192.168.xxx.xxx or 10.xxx.xxx.xxx.

  2. Enable your remote login on your mac following steps from here: http://osxdaily.com/2011/09/30/remote-login-ssh-server-mac-os-x/.

  3. Create a SOCKS proxy into your computer that allows for external traffic. First open up a terminal window, then run this command (replacing X's with your ip address or domain, and username with the user you usually SSH into your computer with, you can also find your login username when you enable remote login):

     ssh -N -gv -D 1080 username@XXX.XXX.XXX.XXX
    

    Note you need to update username here to your Mac's login username, and XXX.XXX.XXX.XXX to your Mac's IP.

    If you do this correctly, you'll be asked to authenticate/login. Once logged in, you'll see a slew of text, at the end of which you'll see something like:

     debug1: Local connections to *:1080 forwarded to remote address socks:0
     debug1: Local forwarding listening on 0.0.0.0 port 1080.
    

    You now have a SOCKS proxy set up that can accept external traffic. Leave this running.

  4. Fire up your text editor, because we need to create a PAC (Proxy-auto-config) file so that the iPad can use this SOCKS proxy.

  5. Create a file with an extension of .pac (i.e. myProxy.pac)

  6. Paste the following into it, replacing X's with your work computer's IP, and Y's with the port you used for the SOCKS proxy (1080 in this example):

     function FindProxyForURL(url, host) {
     	return "SOCKS XXX.XXX.XXX.XXX:YYYY";
     }
    
  7. Save this file, and make it accessible to the iPad. An easy way to do this is to throw it up on dropbox, or other cloud storage your iPad has access to.

    You can also open a new terminal window, cd to the folder containing the PAC file, and type following command: python -m SimpleHTTPServer, then you can use the URL http://XXX.XXX.XXX.XXX:8000/myProxy.pac in the steps below. Notice if you use other file name for the pac file, you need to modify the URL accordingly.

On the iPad

  1. Open up settings > wifi.
  2. Click on the blue arrow next to your wifi connection.
  3. Scroll to the bottom where there is a section for HTTP Proxy.
  4. Select Auto from this section.
  5. In the URL field, key in the URL of the *.pac file you created and made web-accessible.

Voila, your iOS device should now have the network characteristics of your work computer, and all traffic from the iOS device should go through it. You can verify this by watching the SOCKS proxy running in your terminal. When you try to access a website on the iPad, you should see a connection being made in the SOCKS proxy terminal window.

bibliography

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment