Created
May 9, 2018 22:07
-
-
Save 7h3rAm/fd0ad84c6c3324b3a9d0be9f9ccdb4c5 to your computer and use it in GitHub Desktop.
Check if connected via Tor
This file contains hidden or 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 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