Skip to content

Instantly share code, notes, and snippets.

@miclovich
Forked from jefftriplett/tor.py
Created July 14, 2018 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miclovich/5ffbb42a3d4d25b0409d35d64d346ce1 to your computer and use it in GitHub Desktop.
Save miclovich/5ffbb42a3d4d25b0409d35d64d346ce1 to your computer and use it in GitHub Desktop.
Python Requests + Tor (Socks5)
"""
setup:
pip install requests
pip install requests[socks]
super helpful:
- http://packetforger.wordpress.com/2013/08/27/pythons-requests-module-with-socks-support-requesocks/
- http://docs.python-requests.org/en/master/user/advanced/#proxies
"""
import requests
proxies = {
'http': 'socks5://127.0.0.1:9150',
'https': 'socks5://127.0.0.1:9150'
}
def main():
url = 'http://ifconfig.me/ip'
response = requests.get(url)
print('ip: {}'.format(response.text.strip()))
response = requests.get(url, proxies=proxies)
print('tor ip: {}'.format(response.text.strip()))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment