使用Stem从Python更改Tor IP

时间:2016-01-12 00:21:43

标签: python tor stem

规格(MacOSx - 最新版本,Python 3.5,适用于Mac的Stem和Tor浏览器)

我刚开始了解Tor的更多信息,我想从Python脚本中更改我的Tor路径。

from stem import Signal
from stem.control import Controller
from stem import CircStatus

def getIP():
    with Controller.from_port(port = 9151) 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)

def newIP():
    with Controller.from_port(port = 9151) as controller:
        controller.authenticate()
        controller.signal(Signal.NEWNYM)
        print("\n\nNEW IP, NEW IP\n\n")

getIP()
newIP()
getIP()

但是上面的代码并没有暗示两个getIP()之间的新ip。 我检查了连接是否正确:

telnet localhost 9151
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

你能帮我理解为什么我不能这样做?

此致

的Jérémy。

0 个答案:

没有答案