Skip to content

Instantly share code, notes, and snippets.

@atao
Last active February 6, 2024 21:08
Show Gist options
  • Save atao/e5bdee72501b94d3aa9ddf9b5399792f to your computer and use it in GitHub Desktop.
Save atao/e5bdee72501b94d3aa9ddf9b5399792f to your computer and use it in GitHub Desktop.
Check Tor exit node IP
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from lxml import html
proxy_url = "socks5://localhost:9050"
proxies = {"http": proxy_url, "https": proxy_url}
r = requests.Session()
r.proxies.update(proxies)
try:
response = r.get("https://check.torproject.org", proxies=proxies)
except Exception as e:
print(e)
exit(2)
if response.status_code == 200:
tree = html.fromstring(response.text)
data = tree.xpath('//div[@class="content"]')
for p in data:
print(p.xpath('.//h1/text()')[0].strip())
print(p.xpath('.//p/text()')[0],p.xpath('.//p/strong/text()')[0])
else:
print("Request error")
exit(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment