The IT Alchemy Lab really doesn't have any set "purpose" to speak of. It is more about the IT technologies and issues I come across in my day-to-day business, meetings and chats (lunches, coffee and drinks) with my IT colleagues and friends.

Blog Archive

Wednesday, February 13, 2013

Command Line Socks Proxy commands on the Mac

Firewalls always cause developers problems (and I do not mean in the negative context), trying to hit code sites, blogs or other crowd sourcing sites ... after a little research I have come across a little trick that will get the job done

Step 1: create the connectivity file
standard ssh command, dropped into a shell script with the port forwarding flag added:
file:
socks.ssh
content:

#!/bin/bash
ssh -D 1080 username@myhomeserver.com


That's it, that simple ... so what did we just do?  SSH -D is for dynamic application-level port forwarding. Its syntax is ssh -D ${port} ${remote host}  This will allow you to drop a SOCKS proxy over an encrypted ssh tunnel, which leads us directly to ...

Step 2: SOCKS over SSH Tunnel
Now lets over ride the Mac security settings and skip all that silly administrative stuff ...

file:
socks.start
content:

#!/bin/bash
echo "Setting Socks Proxy to 'localhost 1080'"
networksetup -setsocksfirewallproxy "Wi-Fi" localhost 1080
echo "'Wi-Fi' Socks Proxy now pointing to 'localhost 1080'"
networksetup -setsocksfirewallproxy "Ethernet" localhost 1080
echo "'Ethernet' Socks Proxy now pointing to 'localhost 1080'"


This will point all of your outgoing data through your ssh tunnel - averting the firewall and security setup by your administrators

Now we need a way to stop/disable these settings:

file:
socks.stop
content:

#!/bin/bash
echo "Disabling Socks Proxy from 'localhost 1080'"
networksetup -setsocksfirewallproxystate "Wi-Fi" off
networksetup -setsocksfirewallproxystate "Ethernet" off
echo "'Wi-Fi' and 'Ethernet' Socks Proxy now set to 'off'"

Pretty simple ... you will need to set the files as executable: chmod +x socks.ssh socks.start socks.stop




No comments:

About Me

My photo
Don't tell people how to do things, tell them what to do and let them surprise you with their results. --General George S. Patton
Open Source Links | Sourceforge | Slashdot | Open Source