Last active
March 23, 2017 16:51
-
-
Save theasder/6e2a9a5948d9487eae16a5e9fc0feb71 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 urllib.request | |
import stem.process | |
from user_agent import generate_user_agent | |
import time | |
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 | |
# TODO random names, locations and languages | |
values = {'name' : 'Michael Foord', | |
'location' : 'Northampton', | |
'language' : 'Python' } | |
url = 'http://checkip.amazonaws.com/' | |
headers = { 'User-Agent' : generate_user_agent() } | |
data = urllib.parse.urlencode(values) | |
data = data.encode('ascii') | |
req = urllib.request.Request(url, data, headers) | |
api_response = urllib.request.urlopen(req).read() | |
print(api_response) | |
time.sleep(3) | |
tor_process.kill() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment