2

规格(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 '^]'.

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

问候,

杰里米。

4

0 回答 0