Change Tor IP from Python with Stem
<p>Specs (MacOSx - Last version , Python 3.5 , Stem and Tor Browser for Mac)</p>

<p>I just start to learn more about Tor and i wanted to change my Tor route from Python Script.</p>

<pre><code>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()
</code></pre>

<p>But the above code doesn't negociate a new ip between the two getIP().
I checked that the connection was right :</p>

<pre><code>telnet localhost 9151
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
</code></pre>

<p>Could you help me to understand why can't i do it ?</p>

<p>Regards,</p>

<p>Jérémy.</p>