From ac294636cc6e5c9374d0366cb13e2848074e7511 Mon Sep 17 00:00:00 2001 From: AntiTree Date: Sat, 2 Jul 2016 15:40:02 -0400 Subject: [PATCH] Modifying to support control port on the host --- util/control_port.py | 31 +++++++++++++++++++++++++++++++ util/get_consensus.py | 7 +++++++ util/read_consensus.py | 9 +++++++++ 3 files changed, 47 insertions(+) create mode 100644 util/control_port.py create mode 100644 util/get_consensus.py create mode 100644 util/read_consensus.py diff --git a/util/control_port.py b/util/control_port.py new file mode 100644 index 0000000..3fb5858 --- /dev/null +++ b/util/control_port.py @@ -0,0 +1,31 @@ +# Connects to the control port to test that the private network is working +import sys +import getpass +import stem.connection +import stem.socket + +try: + control_socket = stem.socket.ControlPort(port = 9051) +except stem.SocketError as exc: + print 'Unable to connect to port 9051 (%s)' % exc + sys.exit(1) + +try: + stem.connection.authenticate(control_socket) +except stem.connection.IncorrectSocketType: + print 'Please check in your torrc that 9051 is the ControlPort.' + print 'Maybe you configured it to be the ORPort or SocksPort instead?' + sys.exit(1) +except stem.connection.MissingPassword: + controller_password = getpass.getpass('Controller password: ') + + try: + stem.connection.authenticate_password(control_socket, controller_password) + except stem.connection.PasswordAuthFailed: + print 'Unable to authenticate, password is incorrect' + sys.exit(1) +except stem.connection.AuthenticationFailure as exc: + print 'Unable to authenticate: %s' % exc + sys.exit(1) + +print("Successfully authenticated") diff --git a/util/get_consensus.py b/util/get_consensus.py new file mode 100644 index 0000000..9b5b962 --- /dev/null +++ b/util/get_consensus.py @@ -0,0 +1,7 @@ +from stem.control import Controller + +with Controller.from_port(port = 9051) as controller: + controller.authenticate("balls") + + for desc in controller.get_network_statuses(): + print("found relay %s (%s)" % (desc.nickname, desc.fingerprint)) diff --git a/util/read_consensus.py b/util/read_consensus.py new file mode 100644 index 0000000..5d3399d --- /dev/null +++ b/util/read_consensus.py @@ -0,0 +1,9 @@ +from stem.descriptor import parse_file +import sys + +try: + path = sys.argv[1] + for desc in parse_file(path): + print('found relay %s (%s)' % (desc.nickname, desc.fingerprint)) +except IOError: + print("File not found. make sure you supply it with a cached consensus file location: %s" % path)