1

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?

1
  • Could you describe exactly what you have done so far? And what are you error messages? Commented Mar 6, 2013 at 15:02

2 Answers 2

1

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()
Sign up to request clarification or add additional context in comments.

2 Comments

But now, can't find how to renew the address
NOTE: The new SOCKS port seems to be 9150. I literally spent an hour, disabling the firewall etc. trying to figure out why it didn't connect...
0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.