Modifying to support control port on the host

This commit is contained in:
AntiTree 2016-07-02 15:40:02 -04:00
parent 6ab84f60e9
commit ac294636cc
3 changed files with 47 additions and 0 deletions

31
util/control_port.py Normal file
View File

@ -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")

7
util/get_consensus.py Normal file
View File

@ -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))

9
util/read_consensus.py Normal file
View File

@ -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)