Reputation: 1939
I am trying to use TOR with Urllib as given in How to change Tor identity in Python?. However I am not able to understand where shall I find the configuration files.
can anyone give a easier solution so that I can generate new ips using TOR from python?
Upvotes: 1
Views: 1211
Reputation: 2954
See stem's client usage tutorials for examples of making a python socket over tor. That said, please be careful about creating new identities. Doing so puts a high load on the Tor network (for more about this see here).
Upvotes: 0
Reputation: 31
This works for me
import socks import socket def create_connection(address, timeout=None, source_address=None): sock = socks.socksocket() sock.connect(address) return sock
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
# patch the socket module
socket.socket = socks.socksocket
socket.create_connection = create_connection
import urllib2
print urllib2.urlopen('http://icanhazip.com').read()
import mechanize
from mechanize import Browser
br = Browser()
print br.open('http://icanhazip.com').read()
Upvotes: 1