1

我一直在寻找映射 tor 的方法,并查看地址是如何分配的,但我需要能够知道我在任何给定时间使用的入口节点的 IP 地址。

不太确定从哪里开始,因为我只不过是一个熟练的程序员(python),并且倾向于根据需要学习一些零碎的东西。任何指向要使用的命令的指针都将不胜感激。

我确实认为在中间节点上运行 wireshark 可能是最简单的方法,但需要一台额外的机器,我现在没有敲门。

4

3 回答 3

2

实际上,这与我们的常见问题解答条目之一非常相似。要获取当前电路的 IP 地址,您可以使用stem ...

from stem import CircStatus
from stem.control import Controller

with Controller.from_port() as controller:
  controller.authenticate()

  for circ in controller.get_circuits():
    if circ.status != CircStatus.BUILT:
      continue  # skip circuits that aren't yet usable

    entry_fingerprint = circ.path[0][0]
    entry_descriptor = controller.get_network_status(entry_fingerprint, None)

    if entry_descriptor:
      print "Circuit %s starts with %s" % (circ.id, entry_descriptor.address)
    else:
      print "Unable to determine the address belonging to circuit %s" % circ.id

这提供了类似的输出...

atagar@morrigan:~/Desktop/stem$ python example.py 
Circiut 15 starts with 209.222.8.196
Circiut 7 starts with 209.222.8.196

希望这可以帮助!-达米安

于 2013-09-02T16:57:34.383 回答
1

txtorcon是用 python 编写的 Tor 库,它将为您提供所需的所有信息。请参阅 /examples-files 以获取指导。

如有必要,请在 github 上提交功能请求

于 2013-09-01T20:29:11.617 回答
0

您还可以尝试基于 txtorcon 的 carml ( http://carml.readthedocs.org/en/latest/ )。" carml circ --list --verbose" 会给你你想要的信息。

为完整起见,以下是使用 txtorcon 执行上述操作的方法:

#!/usr/bin/env/python                                                                                                                              

from twisted.internet.task import react
from twisted.internet.defer import inlineCallbacks
import txtorcon

@inlineCallbacks
def main(reactor):
    state = yield txtorcon.build_local_tor_connection(reactor)
    for circuit in state.circuits.values():
        first_relay = circuit.path[0]
        print "Circuit {} first hop: {}".format(circuit.id, first_relay.ip)

if __name__ == '__main__':
    react(main)
于 2015-03-16T18:53:34.800 回答