def __init__(self, main):
     from stem.connection import connect
     #super(TorBootstrap, self).__init__(main)
     QtCore.QThread.__init__(self, parent=None)
     self.controller = connect()
     self.signal = QtCore.SIGNAL("signal")
     self.previous_status = ''
     self.bootstrap_percent = 0
 def __init__(self, main):
     from stem.connection import connect
     #super(TorBootstrap, self).__init__(main)
     QtCore.QThread.__init__(self, parent=None)
     self.controller = connect()
     self.signal = QtCore.SIGNAL("signal")
     self.previous_status = ''
     self.bootstrap_percent = 0
Пример #3
0
 def start(self):
     # force new ip address
     controller = connect()
     controller.authenticate(password=password)
     controller.signal("NEWNYM")
     ip = "socks5://localhost:9050"
     self.session = self.get_session(ip)
     self.session.proxies = dict(http=ip, https=ip)
     return "localhost"
Пример #4
0
def time_consensus_sanity_check(unixtime):
    error = ""
    status = "ok"
    consensus_valid_after_str = ""
    consensus_valid_until_str = ""

    try:
        controller = connect()
    except BaseException:
        status = "error"
        error = "Could not open Tor control connection. error: " + \
            str(sys.exc_info()[0])
        return status, error, consensus_valid_after_str, consensus_valid_until_str

    try:
        consensus_valid_after_str = controller.get_info(
            "consensus/valid-after")
        consensus_valid_until_str = controller.get_info(
            "consensus/valid-until")
    except BaseException:
        status = "error"
        error = "Could not request from Tor control connection. error: " + \
            str(sys.exc_info()[0])
        return status, error, consensus_valid_after_str, consensus_valid_until_str

    try:
        controller.close()
    except BaseException:
        pass

    try:
        consensus_valid_after_unixtime = parse(
            consensus_valid_after_str).strftime('%s')
        consensus_valid_until_unixtime = parse(
            consensus_valid_until_str).strftime('%s')

        if int(unixtime) > int(consensus_valid_after_unixtime):
            pass
        else:
            status = "slow"

        if int(unixtime) > int(consensus_valid_until_unixtime):
            status = "fast"
        else:
            pass
    except BaseException:
        try:
            controller.close()
        except BaseException:
            pass
        error = "Unexpected error: " + str(sys.exc_info()[0])
        status = "error"

    return status, error, consensus_valid_after_str, consensus_valid_until_str
Пример #5
0
        def doit():
            self.controller = connect(control_port=('127.0.0.1',
                                                    settings.TORD_PORT))

            if self.controller:
                logging.info("Tord version: " +
                             str(self.controller.get_version()))
            else:
                logging.error("Unable to connect to local 'tord' server")
                if raise_on_error:
                    raise RuntimeError("No local 'tord' server")

            return self.controller
Пример #6
0
def connecTor():
    controller = connect()
    controller.authenticate()
    controller.signal(Signal.NEWNYM)
    print("Connected to Tor, running version %s," % controller.get_version())
    
    base = json.loads(requests.get('http://httpbin.org/ip').text)
    baseIP = base["origin"].split(',')
    
    tor = json.loads(conn.get('http://httpbin.org/ip').text)
    torIP = tor["origin"].split(',')
    
    print("Base IP address: " + baseIP[0] +
          "\n Tor connection IP: " + torIP[0] + "\n\n")
    
    if not controller:
        print("ERROR: Unable to establish connection to Tor network. Existing.")
        sys.exit(1)
Пример #7
0
def connectify():
    controller = connect()
    controller.authenticate()
    controller.signal(Signal.NEWNYM)
    print('Tor is running version %s' % controller.get_version())

    # origin ip address
    origin = json.loads(requests.get('http://httpbin.org/ip').text)
    nonTor = origin["origin"].split(',')

    # ip address when using the tor proxy connection
    tOrigin = json.loads(session.get('http://httpbin.org/ip').text)
    tOriginArr = tOrigin["origin"].split(',')

    print('Origin IP Address: ' + nonTor[0] + '           IP Over Tor: ' +
          tOriginArr[0])
    if not controller:
        # exit if unable to get a connection to the tor network
        print(
            'Attempt to establish a connection with the Tor network has failed. TorCrawl will now close...'
        )
        sys.exit(1)
Пример #8
0
failures = {}
for d in bloblist:
    for relay in d['path']:
        if 'failure' in d:
            if relay not in failures:
                failures[relay] = [d]
            else:
                failures[relay].append(d)
        else:
            if relay not in measurements:
                measurements[relay] = [d['circ_bw']]
            else:
                measurements[relay].append(d['circ_bw'])

# get a tor controller connection, to obtain consensus bandwidth values
tor_connection = connection.connect(
)  # TODO: parametize or read from config...

# ensure that we have server descriptors available
if tor_connection.get_conf("UseMicroDescriptors") in ("auto", "1"):
    tor_connection.set_conf("UseMicroDescriptors", "0")
if tor_connection.get_conf("FetchUselessDescriptors") in ("auto", "1"):
    tor_connection.set_conf("FetchUselessDescriptors", "1")
if not tor_connection.get_conf("FetchDirInfoEarly"):
    tor_connection.set_conf("FetchDirInfoEarly", "1")
if not tor_connection.get_conf("FetchDirInfoExtraEarly"):
    tor_connection.set_conf("FetchDirInfoExtraEarly", "1")

# FIXME: how do we know when all these things are downloaded??

for relay in measurements.keys():
    mean_bw = sum(measurements[relay]) / len(measurements[relay])
Пример #9
0
import sys

from stem.connection import connect

if __name__ == '__main__':
  controller = connect()

  if not controller:
    sys.exit(1)  # unable to get a connection

  print 'Tor is running version %s' % controller.get_version()
  controller.close()
Пример #10
0
def conn():
    controller = connect()
    controller.authenticate()
    return controller
Пример #11
0
 def open_controller(self):
     info = (self.address, self.control_port)
     self.controller = connect(control_port=info,
                               password=self.control_password)
Пример #12
0
 def open(self):
     """Establishes a connection to the Tor server"""
     info = (self.address, self.port)
     self.connection = connect(control_port=info, password=self.password)