Skip to content

Instantly share code, notes, and snippets.

@fabian-mv
Created July 26, 2020 21:32
Show Gist options
  • Save fabian-mv/dd5b52743209745714c5ee185d51da40 to your computer and use it in GitHub Desktop.
Save fabian-mv/dd5b52743209745714c5ee185d51da40 to your computer and use it in GitHub Desktop.
script that checks if TOR service is running and working properly
#!/bin/bash
until $(systemctl is-active --quiet tor.service)
do
printf "Tor is \u001b[31mINACTIVE\u001b[0m, activating...\n"
sudo systemctl start tor.service
done
printf "Tor is \u001b[32mACTIVE\u001b[0m, checking IP address...\n"
TOR=$(curl --silent -x socks5h://127.0.0.1:9050 'http://httpbin.org/ip' | tac | tac | grep -Eo "([0-9]{1,3}[\.]){3}[0-9]{1,3}")
NONTOR=$(curl --silent 'http://httpbin.org/ip' | tac | tac | grep -Eo "([0-9]{1,3}[\.]){3}[0-9]{1,3}")
CODE=0
if [[ "$TOR" != "$NONTOR" ]]
then
printf "Your IP address is \u001b[32mHIDDEN\u001b[0m.\n"
else
printf "Error: Your IP address is \u001b[31mNOT HIDDEN.\u001b[0m\n"
CODE=1
fi
printf "Real IP address: \u001b[34m%s\u001b[0m\n" "$NONTOR"
printf "Routed IP address: \u001b[34m%s\u001b[0m\n" "$TOR"
echo
exit $CODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment