Skip to content

Instantly share code, notes, and snippets.

@ehmo
Created November 9, 2011 00:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ehmo/1349819 to your computer and use it in GitHub Desktop.
Save ehmo/1349819 to your computer and use it in GitHub Desktop.
Request a new IP address from TOR in Python
def NewTorIP():
s = socket.socket()
s.connect(('localhost', 9051))
s.send("AUTHENTICATE\r\n")
r = s.recv(1024)
if r.startswith('250'):
s.send("signal NEWNYM\r\n")
r = s.recv(1024)
if r.startswith('250'):
return True
else:
return False
else:
return False
@efraim-il
Copy link

efraim-il commented Oct 25, 2016

It doesn't work...

@ehmo
Copy link
Author

ehmo commented Aug 13, 2017

It works well, you just need to change the authentication in the torrc config file
CookieAuthentication 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment