如何使用Python和Stem获取Tor ExitNode IP [英] How to get the Tor ExitNode IP with Python and Stem

查看:108
本文介绍了如何使用Python和Stem获取Tor ExitNode IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取Tor使用的外部IP,如所述

I'm trying to get the external IP that Tor uses, as mentioned here. When using something like myip.dnsomatic.com, this is very slow. I tried what was suggested in the aforementioned link (python + stem to control tor through the control port), but all you get is circuit's IPs with no assurance of which one is the one on the exitnode, and, sometimes the real IP is not even among the results.

任何帮助将不胜感激.

此外,在此处的底部,Amine提出了一种在Tor中更新身份的方法.有一条指令 controller.get_newnym_wait(),他用来等待直到新连接准备就绪(控制器来自steam.control中的Control),在Steam中没有这样的指令(对不起,我检查了一下,再进行了两次/三次检查,什么都没找到),告诉您Tor正在更改其身份?

Also, from here, at the bottom, Amine suggests a way to renew the identity in Tor. There is an instruction, controller.get_newnym_wait(), which he uses to wait until the new connection is ready (controller is from Control in steam.control), isn't there any thing like that in Steam (sorry, I checked and double/triple checked and couldn't find nothing) that tells you that Tor is changing its identity?

推荐答案

您无需调用geoip站点即可获取出口节点ip.

You can get the exit node ip without calling a geoip site.

这是在另一个stackexchange网站上-

This is however on a different stackexchange site here - https://tor.stackexchange.com/questions/3253/how-do-i-trap-circuit-id-none-errors-in-the-stem-script-exit-used-py

@mirimir发布的他的代码在下面基本上附加了一个流事件侦听器功能,该功能随后用于获取电路ID,电路指纹,最后是出口ip地址-

As posted by @mirimir his code below essentially attaches a stream event listener function, which is then used to get the circuit id, circuit fingerprint, then finally the exit ip address -

#!/usr/bin/python

import functools
import time
from stem import StreamStatus
from stem.control import EventType, Controller

def main():
  print "Tracking requests for tor exits. Press 'enter' to end."
  print

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

    stream_listener = functools.partial(stream_event, controller)
    controller.add_event_listener(stream_listener, EventType.STREAM)

    raw_input()  # wait for user to press enter

def stream_event(controller, event):
  if event.status == StreamStatus.SUCCEEDED and event.circ_id:
    circ = controller.get_circuit(event.circ_id)
    exit_fingerprint = circ.path[-1][0]
    exit_relay = controller.get_network_status(exit_fingerprint)
    t = time.localtime()

    print "datetime|%d-%02d-%02d %02d:%02d:%02d % (t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec)
    print "website|%s" % (event.target)
    print "exitip|%s" % (exit_relay.address)
    print "exitport|%i" % (exit_relay.or_port)
    print "fingerprint|%s" % exit_relay.fingerprint
    print "nickname|%s" % exit_relay.nickname
    print "locale|%s" % controller.get_info("ip-to-country/%s" % exit_relay.address, 'unknown')
    print

这篇关于如何使用Python和Stem获取Tor ExitNode IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆