[go: up one dir, main page]

File: connect.py

package info (click to toggle)
txtorcon 18.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,672 kB
  • sloc: python: 17,521; makefile: 227
file content (24 lines) | stat: -rw-r--r-- 812 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python

from __future__ import print_function
from twisted.internet.task import react
from twisted.internet.defer import inlineCallbacks
from twisted.internet.endpoints import TCP4ClientEndpoint
import txtorcon


@react
@inlineCallbacks
def main(reactor):
    ep = TCP4ClientEndpoint(reactor, "localhost", 9051)
    # or (e.g. on Debian):
    # ep = UNIXClientEndpoint(reactor, "/var/run/tor/control")
    tor = yield txtorcon.connect(reactor, ep)
    print("Connected to Tor {version}".format(version=tor.protocol.version))

    state = yield tor.create_state()
    # or:
    # state = yield txtorcon.TorState.from_protocol(tor.protocol)
    print("Tor state created. Circuits:")
    for circuit in state.circuits.values():
        print("  {circuit.id}: {circuit.path}".format(circuit=circuit))