Skip to content

Instantly share code, notes, and snippets.

@7h3rAm
Created May 9, 2018 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 7h3rAm/fd0ad84c6c3324b3a9d0be9f9ccdb4c5 to your computer and use it in GitHub Desktop.
Save 7h3rAm/fd0ad84c6c3324b3a9d0be9f9ccdb4c5 to your computer and use it in GitHub Desktop.
Check if connected via Tor
#!/usr/bin/env python3
import requests
proxies = {
"http": "socks5h://localhost:9050",
"https":"socks5h://localhost:9050"
}
def get_public_ip(usetor=False):
return requests.get("https://api.ipify.org/?format=json", proxies=proxies if usetor else {}).json()
def check_tor(ipaddr=None, usetor=False):
if not ipaddr:
ipaddr = get_public_ip(usetor=usetor)["ip"]
res = requests.post(
"https://torstatus.blutmagie.de/tor_exit_query.php",
data={"DestinationIP": "", "DestinationPort": "", "QueryIP": ipaddr}
)
return True if "-The IP Address you entered matches one or more active Tor servers-" in res.text else False
if __name__ == "__main__":
print(check_tor())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment