Created
March 23, 2017 09:03
-
-
Save theasder/caed9d979ad77e5821be8cc84369878a to your computer and use it in GitHub Desktop.
This file contains 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
import socket | |
import socks | |
import urllib2 | |
import stem.process | |
ipcheck_url = 'http://checkip.amazonaws.com/' | |
SOCKS_PORT = 9150 | |
tor_process = stem.process.launch_tor_with_config( | |
config = { | |
'SocksPort': str(SOCKS_PORT), | |
'ExitNodes': '{ru}', | |
}, | |
) | |
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', SOCKS_PORT) | |
socket.socket = socks.socksocket | |
api_response = urllib2.urlopen(ipcheck_url).read() | |
print(api_response) | |
tor_process.kill() | |
# launch `sudo killall tor` to kill all tor processes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment