Twisted-based Tor controller client, with state-tracking and configuration abstractions. https://txtorcon.readthedocs.org https://github.com/meejah/txtorcon
Project description
txtorcon
docs: https://txtorcon.readthedocs.org or http://fjblvrw2jrxnhtg67qpbzi45r7ofojaoo3orzykesly2j3c2m3htapid.onion/
torsocks git clone git://fjblvrw2jrxnhtg67qpbzi45r7ofojaoo3orzykesly2j3c2m3htapid.onion/txtorcon.git
MIT-licensed;
Python 3.8+, PyPy 7.3.7+;
Ten Thousand Feet
txtorcon is an implementation of the control-spec for Tor using the Twisted networking library for Python.
This is useful for writing utilities to control or make use of Tor in event-based Python programs. If your Twisted program supports endpoints (like twistd does) your server or client can make use of Tor immediately, with no code changes. Start your own Tor or connect to one and get live stream, circuit, relay updates; read and change config; monitor events; build circuits; create onion services; etcetera (ReadTheDocs).
Some Possibly Motivational Example Code
from twisted.internet.task import react
from twisted.internet.defer import inlineCallbacks, ensureDeferred
from twisted.internet.endpoints import UNIXClientEndpoint
import treq
import txtorcon
async def main(reactor):
tor = await txtorcon.connect(
reactor,
UNIXClientEndpoint(reactor, "/var/run/tor/control")
)
print("Connected to Tor version {}".format(tor.version))
url = u'https://www.torproject.org:443'
print(u"Downloading {}".format(repr(url)))
resp = await treq.get(url, agent=tor.web_agent())
print(u" {} bytes".format(resp.length))
data = await resp.text()
print(u"Got {} bytes:\n{}\n[...]{}".format(
len(data),
data[:120],
data[-120:],
))
print(u"Creating a circuit")
state = await tor.create_state()
circ = await state.build_circuit()
await circ.when_built()
print(u" path: {}".format(" -> ".join([r.ip for r in circ.path])))
print(u"Downloading meejah's public key via above circuit...")
config = await tor.get_config()
resp = await treq.get(
u'https://meejah.ca/meejah.asc',
agent=circ.web_agent(reactor, config.socks_endpoint(reactor)),
)
data = await resp.text()
print(data)
@react
def _main(reactor):
return ensureDeferred(main(reactor))
Try It Now On Debian/Ubuntu
For example, serve some files via an onion service (aka hidden service):
$ sudo apt-get install --install-suggests python3-txtorcon
$ twistd -n web --port "onion:80" --path ~/public_html
Read More
All the documentation starts in docs/index.rst. Also hosted at txtorcon.rtfd.org.
You’ll want to start with the introductions (hosted at RTD).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file txtorcon-24.8.0.tar.gz
.
File metadata
- Download URL: txtorcon-24.8.0.tar.gz
- Upload date:
- Size: 312.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | befe19138d9c8c5307b6ee6d4fe446d0c201ffd1cc404aeb265ed90309978ad0 |
|
MD5 | c3e9d8fe545effa09c0e43612c91ca17 |
|
BLAKE2b-256 | b99f7815b07d8bc775d9578d9131267bb7ce3e91e31305688736ed796ae724d1 |
File details
Details for the file txtorcon-24.8.0-py3-none-any.whl
.
File metadata
- Download URL: txtorcon-24.8.0-py3-none-any.whl
- Upload date:
- Size: 261.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3d0871a19c2ecaaae9e2c13b302a78b169048f5a3c2051069a2ea6ae44232c7 |
|
MD5 | 797bfe4674e911887e0c37b8d6ba10c6 |
|
BLAKE2b-256 | 3c388b12c86c148612722d19bf9d7fdfcbcbc76bdcee5a0abebdbdc1eb14bf7c |