How to determine from the CLI what are intermediary nodes used when running `tor`?
Jul 25, 2:01pm

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:


Method 1: Using 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.

  1. Install nyx: On Debian/Ubuntu:

    bash
    sudo apt install nyx

    On Arch Linux:

    bash
    sudo pacman -S nyx
  2. Run nyx: Start nyx while tor is running:

    bash
    nyx
    • This will display a live dashboard of your Tor client, including the current circuit and the nodes (relays) being used.

Method 2: Using tor Control Port

You can query the Tor control port to get the current circuit information.

  1. Enable the Control Port: Edit your torrc configuration file (usually at /etc/tor/torrc or ~/.torrc) and add:

    text
    ControlPort 9051
    CookieAuthentication 1

    Restart tor:

    bash
    sudo systemctl restart tor
  2. Query the Circuit: Use curl or telnet to query the control port. For example:

    bash
    curl --unix-socket /var/run/tor/control -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "GETINFO circuit-status" --user : 2>/dev/null
    • This will return the current circuit status, including the nodes (relays) in use.

    Alternatively, use telnet:

    bash
    telnet localhost 9051

    Then authenticate (if required) and send:

    text
    GETINFO circuit-status

Method 3: Using torsocks and curl

If 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.

  1. Install torsocks: On Debian/Ubuntu:

    bash
    sudo apt install torsocks

    On Arch Linux:

    bash
    sudo pacman -S torsocks
  2. Query the Circuit: Use torsocks with curl to fetch the circuit information:

    bash
    torsocks curl -s https://check.torproject.org/api/ip | grep -oP '(?<=IP":")[^"]*'
    • This will show the exit node IP. To see the full circuit, you can use:
    bash
    torsocks curl -s https://onionoo.torproject.org/details?type=relay | jq '.relays[] | {nickname, fingerprint, address}'
    • This will list all relays, but you can filter for your specific circuit.

Method 4: Using arm (Anonymizing Relay Monitor)

arm is another command-line tool for monitoring Tor.

  1. Install arm: On Debian/Ubuntu:

    bash
    sudo apt install arm

    On Arch Linux:

    bash
    sudo pacman -S arm
  2. Run arm: Start arm while tor is running:

    bash
    arm
    • This will display a live view of your Tor client, including the current circuit and nodes.

Method 5: Using stem (Python Library)

If you prefer Python, you can use the stem library to query Tor.

  1. Install stem:

    bash
    pip install stem
  2. Run a Python Script: Create a script to query the current circuit:

    python
    from 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})")
    • Run the script:
      bash
      python3 script.py

Summary Table

Methods to Determine Tor Intermediary Nodes
nyx
nyx
Real-time monitoring tool for Tor circuits.
Control Port
curl/telnet
Query Tor's control port for circuit status.
torsocks + curl
torsocks curl
Fetch circuit information via Tor network.
arm
arm
Command-line tool for monitoring Tor circuits.
stem
Python script with stem
Programmatically query Tor circuits using Python.

Would you like help setting up any of these methods?

Jul 25, 2:01pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more