Skip to content

Instantly share code, notes, and snippets.

@szymonrucinski
Last active November 10, 2021 15:16
Show Gist options
  • Save szymonrucinski/aa8db38b11703ac61dfa8f7c817831e1 to your computer and use it in GitHub Desktop.
Save szymonrucinski/aa8db38b11703ac61dfa8f7c817831e1 to your computer and use it in GitHub Desktop.
Setup TOR protocol to surf with any browser on Mac.
#!/usr/bin/env bash
# 'Wi-Fi' or 'Ethernet' or 'Display Ethernet'
INTERFACE=Wi-Fi
# 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 disable_proxy() {
sudo networksetup -setsocksfirewallproxystate $INTERFACE off
echo "$(tput setaf 64)" #green
echo "SOCKS proxy disabled."
echo "$(tput sgr0)" # color reset
echo "Exiting Tor 🧅"
}
trap disable_proxy INT
# trap ctrl-c and call disable_proxy()
# Let's roll
sudo networksetup -setsocksfirewallproxy $INTERFACE 127.0.0.1 9050 off
sudo networksetup -setsocksfirewallproxystate $INTERFACE on
echo "$(tput setaf 64)" # green
echo "SOCKS proxy 127.0.0.1:9050 enabled."
echo "$(tput setaf 136)" # orange
echo "Starting Tor..."
echo "$(tput sgr0)" # color reset
tor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment