[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [tor-relays] How do I get the *current* Tor exit node IP address over the control port?



On 1/27/20 05:47, Mike wrote:
> Hello,
> 
> How do I get the external IP address of the current Tor exit node (the
> one which is in use) without using external services/websites (through
> curl or otherwise) but only through the Tor control port functionality
> (using bash or python3).
> 
> *I have also asked on https://stackoverflow.com/q/59923289

stem's get_circuits() function on a controller.

https://stem.torproject.org/api/control.html#stem.control.Controller.get_circuits

You'll get a list of circuit objects, which each have a path. For each
circuit that is built for the purpose of carrying your traffic to a
non-onion destination, the last item in the path is an exit node.

It's all in the stem documentation. I would familiarize yourself with
it. Also, this is a mailing list for Tor relay operators to talk about
relay operation stuff. tor-talk@ might have been a better place for this.

Note your misconception that there is only **one** circuit or **one**
exit at a time. Not true. Tor may choose to open new circuits for a wide
variety of reasons. The remainder of this email is a copy/paste response
I use on Reddit when people seem to have this misconception.

The mental model of "Tor gives you a new IP address every 10 minutes" is
very inaccurate. There's a tiny grain of truth, but there's a pile of
reasons it isn't really true.

What you're thinking of is the `MaxCircuitDirtiness` torrc option, which
indeed defaults to 10 minutes. Once you start using circuit A, Tor will
no longer attach new streams to it automatically after 10 minutes.
That's what it means more or less.

But there are so many reasons why you might have more than one circuit
for user traffic, each with a different exit node (or none at all, for
onion service circuits).

- Each unique onion service you visit needs its own circuit.
- Maybe you have some very long lived connections (SSH, IRC, etc.) that
are still hanging around on older circuits while your active browsing is
using a newer one.
- Maybe for whatever reason, Tor doesn't think a connection will work
over the "current" circuit (e.g. the exit's `ExitPolicy` or something
dumb and impossible to explain about Tor's internal logic). If this is
the case, it isn't afraid to build a new one.

And that's just talking about Tor. What about Tor Browser?

Tor Browser intelligently separates both the state you receive from
various websites and the connections you make to websites.

If I have https://facebook.com open in tab 1, 2, and 3, all its state
*regardless of the domain it comes from* goes into a single bucket and
all the connections use one (or more) circuits reserved for this
bucket's traffic. If I have https://amazon.com open in tabs 4, 5, and 6,
all its state goes into a different single bucket and all the
connections use a different circuit(s) for their traffic.

So just by browsing multiple websites at the same time, I have more than
one circuit open, and therefore more than one IP.

-- 
Matt
_______________________________________________
tor-relays mailing list
tor-relays@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-relays