I want to monitor the status of running Tor instances.
I am already able to get information via a TCP connection to the control ports. E.g. "GETINFO stream-status" returns data, but I am not able to determine the IP address of the currently chosen exit node.
It would be possible to simply request something like whatismyip.org, but that is too slow and does not scale well.
So what is the best way to get the exit node IP address of a Tor connection?
Tor exit nodes can be detected in a web application's log of connections that have been made to the server, if they include the public source IP address of the transaction initiator.
Tor Exit Nodes are the gateways where encrypted Tor traffic hits the Internet. This means an exit node can be abused to monitor Tor traffic (after it leaves the onion network). It is in the design of the Tor network that locating the source of that traffic through the network should be difficult to determine.
The exit node is the point in which your web traffic leaves the Tor network and is forwarded to your desired destination. The exit node is unable to see your IP address, but it does know what site it's connecting to.
This is a great question! Here's a short script for doing it using stem...
from stem import CircStatus
from stem.control import Controller
with Controller.from_port(port = 9051) as controller:
controller.authenticate()
for circ in controller.get_circuits():
if circ.status != CircStatus.BUILT:
continue
exit_fp, exit_nickname = circ.path[-1]
exit_desc = controller.get_network_status(exit_fp, None)
exit_address = exit_desc.address if exit_desc else 'unknown'
print "Exit relay"
print " fingerprint: %s" % exit_fp
print " nickname: %s" % exit_nickname
print " address: %s" % exit_address
print
Thanks for the question. I've added this to our FAQ.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With