testing data collection using stem

This commit is contained in:
AntiTree 2016-07-02 19:33:18 -04:00
parent 3af351a03d
commit 136dd2f129

View File

@ -1,31 +1,42 @@
# Connects to the control port to test that the private network is working # Connects to the control port to test that the private network is working
import sys
import getpass import getpass
import sys
import stem
import stem.connection import stem.connection
import stem.socket
try: from stem.control import Controller
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: if __name__ == '__main__':
stem.connection.authenticate(control_socket) try:
except stem.connection.IncorrectSocketType: controller = Controller.from_port()
print 'Please check in your torrc that 9051 is the ControlPort.' except stem.SocketError as exc:
print 'Maybe you configured it to be the ORPort or SocksPort instead?' print("Unable to connect to tor on port 9051: %s" % exc)
sys.exit(1) sys.exit(1)
except stem.connection.MissingPassword:
controller_password = getpass.getpass('Controller password: ')
try: try:
stem.connection.authenticate_password(control_socket, controller_password) controller.authenticate()
except stem.connection.PasswordAuthFailed: except stem.connection.MissingPassword:
print 'Unable to authenticate, password is incorrect' pw = getpass.getpass("Controller password: ")
sys.exit(1)
except stem.connection.AuthenticationFailure as exc:
print 'Unable to authenticate: %s' % exc
sys.exit(1)
print("Successfully authenticated") try:
controller.authenticate(password = pw)
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("List of DAs found:")
for desc in controller.get_network_statuses():
print("found relay %s (%s)" % (desc.nickname, desc.address))
print("List of Relays Found:")
for desc in controller.get_microdescriptors():
print("found relay %s (%s)" % (desc.identifier, desc.or_addresses))
print("Tor is running version %s" % controller.get_version())
controller.close()