[Question] ToR nodes and stem library

(Zain) #1

Yo, f0rg here with yet another question. I’m busy creating a script in Python. Basically the issue lies in using ToR as a way to change the IP as the stem lib documentation states:

“An important thing to note is that a new circuit does not necessarily mean a new IP address. Paths are randomly selected based on heuristics like speed and stability. There are only so many large exits in the Tor network, so it’s not uncommon to reuse an exit you have had previously.”

That could be a issue. My question is, how would I efficiently check the IP to make sure it isn’t duplicates? I was thinking of maybe doing something like this in pseudo code , warning this is ugly:


    while(IP ! duplicate):
        get IP # the first time
        if(change_ip == IP):
            run again
except Exception:

    print "Error"

My question is, if I create a function for this… and lets say I use the function in the main function… or whatever… could this possibly work. Thank you in advance. ~Cheers!

–Techno Forg–



Run it first. It looks good so far.
If you want you can try to create an ‘elif statement’ to make sure there aren’t any duplicate IP addresses in your code. It would go in between the ‘if statement’ and the ‘else statement’. But if you want to get even more complicated: use TRUE with the ‘if’, ‘elif’, ‘else statements’ to ensure that you are not getting duplicates. You can also use the ‘elif statements’ to pick IP addresses you want to get, while using TRUE to check it. Basically, using TRUE with your line of code creates a ‘if TRUE do this’, ‘if not do this’ kind of statement.



I think the best way to do so would be setting up a simple app on an external VPS that will just return your IP address. You could use publicly available services to do so, but I personally would not trust them.

Here is a simple flask app that would do exactly that:

from flask import Flask
from flask import request

app = Flask(__name__)

def index():
    return request.remote_addr, 200

Then you can just use python’s requests to get your current IP address, if it does not change, then attempt to change it again. (I actually do not know the stem lib, so no code for changing IP here :stuck_out_tongue: )

>>> import requests
>>> r = requests.get("http://your_vps/")
>>> r.text
>>>#yes, the IP above is fake, for obvious reasons :)

(Zain) #4

Thank you!!! I will look into this!!!

(system) #5

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.