Skip to content

Instantly share code, notes, and snippets.

@sesseor
Created April 30, 2021 20:43
Show Gist options
  • Save sesseor/080ace057095c63b50b319fbb8caf9d7 to your computer and use it in GitHub Desktop.
Save sesseor/080ace057095c63b50b319fbb8caf9d7 to your computer and use it in GitHub Desktop.
Python requests over Tor (Socks5)
#install `tor`
#sudo apt install tor
#sudo service tor start
#install `requests`
#pip3 install requests
#pip3 install requests[socks]
import requests
proxies = {
'http': 'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'
}
def get_ip():
url = 'http://ifconfig.me/ip'
response = requests.get(url).text
print(f'host ip: {response}')
response = requests.get(url, proxies=proxies).text
print(f'tor ip: {response}')
if __name__ == '__main__':
get_ip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment