如何通过控制端口获取Tor出口节点IP地址? [英] How do I get the Tor exit node IP address over the control port?
问题描述
我想监视运行Tor实例的状态。
I want to monitor the status of running Tor instances.
我已经能够通过TCP连接获取信息到控制端口了。
例如GETINFO stream-status返回数据,但我无法确定当前所选退出节点的IP地址。
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.
可以简单地请求类似whatismyip.org,但这太慢了,不能很好地扩展。
It would be possible to simply request something like whatismyip.org, but that is too slow and does not scale well.
那么获得Tor连接的退出节点IP地址的最佳方法是什么?
So what is the best way to get the exit node IP address of a Tor connection?
推荐答案
这是一个很棒的问题!这是一个使用词干的简短脚本...
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.
这篇关于如何通过控制端口获取Tor出口节点IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!