Created
December 15, 2016 23:06
-
-
Save mathiasjakobsen/b241f75e0dc4c491293712ad52599946 to your computer and use it in GitHub Desktop.
'tor' wrapper for macOS, that automatically SOCKS proxy on the active network interface before lift off 🚀
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
#!/usr/bin/env bash | |
# This is a modified version of @kremalicious's original script (https://kremalicious.com/simple-tor-setup-on-mac-os-x/) | |
# The script was hardcoded to a specific network interface. Now it's not ¯\_(ツ)_/¯ | |
# Resolve the current network interface identifier | |
SERVICES=$(networksetup -listnetworkserviceorder | grep 'Hardware Port') | |
while read line; do | |
SNAME=$(echo $line | awk -F "(, )|(: )|[)]" '{print $2}') | |
SDEV=$(echo $line | awk -F "(, )|(: )|[)]" '{print $4}') | |
if [ -n "$SDEV" ]; then | |
ifconfig $SDEV 2>/dev/null | grep 'status: active' > /dev/null 2>&1 | |
if [ "$?" -eq 0 ]; then | |
INTERFACE="$SNAME" | |
fi | |
fi | |
done <<< "$(echo "$SERVICES")" | |
# Ask for the administrator password upfront | |
sudo -v | |
# Keep-alive: update existing `sudo` time stamp until finished | |
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & | |
function output() { | |
echo "$(tput setaf $2)$1$(tput sgr0)" | |
echo " " | |
} | |
# Trap ctrl-c and call disable_proxy() | |
function disable_proxy() { | |
sudo networksetup -setsocksfirewallproxystate $INTERFACE off | |
output "SOCKS proxy disabled.." 136 | |
} | |
trap disable_proxy INT | |
# Let's roll | |
sudo networksetup -setsocksfirewallproxy $INTERFACE 127.0.0.1 9050 off | |
sudo networksetup -setsocksfirewallproxystate $INTERFACE on | |
echo " " | |
output "SOCKS proxy 127.0.0.1:9050 enabled, on the '$INTERFACE' interface.." 136 | |
output "Starting tor 🚀" 64 | |
tor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment