Skip to content

Instantly share code, notes, and snippets.

@lukaszkorecki
Last active April 30, 2017 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaszkorecki/202eb8b49c02fc191d5266a757d805cf to your computer and use it in GitHub Desktop.
Save lukaszkorecki/202eb8b49c02fc191d5266a757d805cf to your computer and use it in GitHub Desktop.
Fast and easy socks proxy setup on OSX: enables proxy, starts the proxy connection and cleans up after itself when its done
#!/usr/bin/env bash
# Enable SOCKS tunnel for given interface, ssh to a remote machine
# and open a SOCKS proxy.
# When cancelled it will disable proxy settings for given interface
# Start with sudo socks.sh if you want it to modify all settings for you
# or just run socks.sh to be prompted on all settings changes
user= # ssh user
host= # ssh host
interface="Wi-Fi" # find with networksetup -listnetworkserviceorder
proxyPort=8080 # proxy port to use
log() {
logger -t SOX -s "$*"
osascript -e "display notification \"$*\" with title \"SOX\""
}
log "Connecting to a proxy on $user@$host:$proxyPort and attaching to interface $interface"
networksetup -setsocksfirewallproxy "$interface" localhost $proxyPort
ssh -D $proxyPort -p 22 $user@$host -t 'while true ; do date;echo Proxying;sleep 30; done'
networksetup -setsocksfirewallproxystate "$interface" off
log "We done, cleaning up"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment