Skip to content

Instantly share code, notes, and snippets.

@llazzaro
Forked from jefftriplett/tor.py
Last active August 29, 2015 14:20
Show Gist options
  • Save llazzaro/b7a4d0c2c485ca80e315 to your computer and use it in GitHub Desktop.
Save llazzaro/b7a4d0c2c485ca80e315 to your computer and use it in GitHub Desktop.
"""
setup:
pip install requesocks
super helpful:
http://packetforger.wordpress.com/2013/08/27/pythons-requests-module-with-socks-support-requesocks/
"""
import requests
import requesocks
session = requesocks.session()
session.proxies = {
'http': 'socks5://127.0.0.1:9150',
'https': 'socks5://127.0.0.1:9150'
}
url = 'http://ifconfig.me/ip'
resp = requests.get(url)
print 'ip: {}'.format(resp.text.strip())
resp = session.get(url)
print 'tor ip: {}'.format(resp.text.strip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment