Last active
December 30, 2024 06:16
-
-
Save sheerun/3885694 to your computer and use it in GitHub Desktop.
Automatic SOCKS proxy setup through SSH connection on Mac OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script for automatic setup of SOCKS proxy through SSH connection. | |
# It automatically teardowns SOCKS configuration before stopping. | |
# It's supposed to work on Mac OS X 10.6+ | |
# | |
# Author: Adam Stankiewicz (@sheerun) | |
# | |
[[ -n "$1" ]] || { echo "Usage: proxy user@example.com"; exit 1; } | |
# get service GUID and NAME (like Wi-Fi) to set SOCKS proxy | |
SERVICE_GUID=`printf "open\nget State:/Network/Global/IPv4\nd.show" | \ | |
scutil | grep "PrimaryService" | awk '{print $3}'` | |
SERVICE_NAME=`printf "open\nget Setup:/Network/Service/$SERVICE_GUID\nd.show" |\ | |
scutil | grep "UserDefinedName" | awk -F': ' '{print $2}'` | |
# command to disble socks proxy after at the end | |
finally() { sudo networksetup -setsocksfirewallproxystate "$SERVICE_NAME" off; } | |
# enable socks proxy in system configuration | |
sudo networksetup -setsocksfirewallproxy "$SERVICE_NAME" 127.0.0.1 1080 && | |
ssh $1 -N -D 1080 | |
trap finally INT | |
finally |
Yep can confirm, works on osx 10.11 without problems, IP exclusion list in system settings is respected too
would be nice if script had -C option for compressed ssh connection on slow networks
Hi @sheerun
I have been using this script for >10 years without any major issue. It helped me and my colleagues a lot. Thank you very much.
Presumably after upgrading my OS to Ventura, I cannot use my IMAP or SMTP servers when the SOCKS proxy is enabled. I understand that it is not caused by the nature of this script but something updated on the macOS or Apple Mail side. I am wondering if anyone here knows how to fix this issue.
Disabling the firewall in System Settings temporarily resolved the issue.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested in OS X 10.11.4, works perfectly ;-).