Skip to content

Instantly share code, notes, and snippets.

@arulrajnet
Created May 3, 2015 10:32
Show Gist options
  • Save arulrajnet/9df385cdb70d8a945686 to your computer and use it in GitHub Desktop.
Save arulrajnet/9df385cdb70d8a945686 to your computer and use it in GitHub Desktop.
TOR ip renew script using pytorctl https://github.com/aaronsw/pytorctl which is a python based module to interact with the Tor Controller.
from TorCtl import TorCtl
import urllib2
user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'
headers={'User-Agent':user_agent}
def request(url):
def _set_urlproxy():
proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
_set_urlproxy()
request=urllib2.Request(url, None, headers)
return urllib2.urlopen(request).read()
def renew_connection():
conn = TorCtl.connect(controlAddr="127.0.0.1", controlPort=9051, passphrase="Password12")
conn.send_signal("NEWNYM")
conn.close()
for i in range(0, 10):
renew_connection()
print request("http://curlmyip.com/")
@arulrajnet
Copy link
Author

For TOR with Privoxy use the docker container

https://registry.hub.docker.com/u/arulrajnet/torprivoxy/

Installation

apt-get install git
apt-get install python-dev python-pip
wget --no-check-certificate https://github.com/aaronsw/pytorctl/archive/master.zip
unzip master.zip
pip install pytorctl-master/

Then to run python tor_ip_renew.py

you can configure the TOR controller password in the above script.

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