To determine the intermediary nodes (relays) used in a Tor circuit from the command line, you can use the tor client itself or tools like torsocks and curl to query the Tor network. Here’s how you can do it:
tor with nyx (Recommended)nyx is a command-line monitoring tool for Tor. It provides a real-time view of your Tor client, including the current circuit and nodes.
Install nyx:
On Debian/Ubuntu:
bashsudo apt install nyx
On Arch Linux:
bashsudo pacman -S nyx
Run nyx:
Start nyx while tor is running:
bashnyx
tor Control PortYou can query the Tor control port to get the current circuit information.
Enable the Control Port:
Edit your torrc configuration file (usually at /etc/tor/torrc or ~/.torrc) and add:
textControlPort 9051 CookieAuthentication 1
Restart tor:
bashsudo systemctl restart tor
Query the Circuit:
Use curl or telnet to query the control port. For example:
bashcurl --unix-socket /var/run/tor/control -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "GETINFO circuit-status" --user : 2>/dev/null
Alternatively, use telnet:
bashtelnet localhost 9051
Then authenticate (if required) and send:
textGETINFO circuit-status
torsocks and curlIf you want to see the circuit for a specific connection, you can use torsocks with curl to fetch the circuit information from the Tor network.
Install torsocks:
On Debian/Ubuntu:
bashsudo apt install torsocks
On Arch Linux:
bashsudo pacman -S torsocks
Query the Circuit:
Use torsocks with curl to fetch the circuit information:
bashtorsocks curl -s https://check.torproject.org/api/ip | grep -oP '(?<=IP":")[^"]*'
bashtorsocks curl -s https://onionoo.torproject.org/details?type=relay | jq '.relays[] | {nickname, fingerprint, address}'
arm (Anonymizing Relay Monitor)arm is another command-line tool for monitoring Tor.
Install arm:
On Debian/Ubuntu:
bashsudo apt install arm
On Arch Linux:
bashsudo pacman -S arm
Run arm:
Start arm while tor is running:
basharm
stem (Python Library)If you prefer Python, you can use the stem library to query Tor.
Install stem:
bashpip install stem
Run a Python Script: Create a script to query the current circuit:
pythonfrom stem.control import Controller with Controller.from_port(port=9051) as controller: controller.authenticate() for circuit in controller.get_circuits(): print(f"Circuit {circuit.id}:") for node in circuit.path: print(f" - {node.nickname} ({node.fingerprint})")
bashpython3 script.py
nyxnyxcurl/telnettorsocks + curltorsocks curlarmarmstemstemWould you like help setting up any of these methods?
Vibe can make mistakes. Check answers. Learn more