I do not vouch for the readiness, or standards of this release. There are many things I would remake in it, I just do not have a need for it right now.
When I was using my item gen, I made a Tor module that uses TorCTL to easily create connections, test connections, change identity, and check IP. From what I was doing with TorCTL it did not have an error check if Tor wasn't actually running, so I had to initialize it all through a socket object, which lead to this. It's pretty simple, kinda dirty but maybe someone here will have a use for it, or will be able to learn something about implementing Tor into their projects. This module was made based off me running the minimal tor package, not vindilia, but they should both work if you set the proper ports and password.
tor.py
settings.iniPHP Code:
import requests
import socks
import socket
import sys
import time
from ConfigParser import ConfigParser
from TorCtl import TorCtl
def parse_ini(ini_file='settings.ini'):
config = ConfigParser()
try:
config.read(ini_file)
tor.update(dict(config.items('Tor')))
except:
raise Exception('Settings missing or incorrect.')
def connect():
parse_ini()
while 'control' not in tor:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect((tor['sockslistenaddress'], int(tor['controlport'])))
tor['control'] = TorCtl.Connection(sock)
tor['control'].authenticate(tor['password'])
except socket.error:
print 'Unable to connect to Tor.'
raw_input('Press any key to exit.')
sys.exit()
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5,
tor['sockslistenaddress'],
int(tor['socksport']))
socket.socket = socks.socksocket
socket.create_connection = create_connection
httpget = requests.get('http://jsonip.com/').json()
tor['ip'] = httpget['ip']
def create_connection(address, timeout=None, source_address=None):
sock = socks.socksocket()
sock.connect(address)
return sock
def new_id():
new_ip = tor['ip']
while new_ip == tor['ip']:
tor['control'].send_signal("NEWNYM")
httpget = requests.get('http://jsonip.com/').json()
new_ip = httpget['ip']
time.sleep(.5)
tor['ip'] = new_ip
tor = {}
PHP Code:
[Tor]
SocksListenAddress=127.0.0.1
SocksPort=9051
ControlPort=9151
Password=test