Package: toripchanger
TorIpChangerA simple workaround forTor IP changing behavior: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.InstallationpipinstalltoripchangerDependenciesTorIpChangerassumes you have installed and setup Tor and Privoxy, for example following steps mentioned in these tutorials:A step-by-step guide how to use Python with Tor and PrivoxyCrawling anonymously with Tor in PythonAlternative link (Gist)for "Crawling anonymously with Tor in Python"Or, when using Docker, simply usehttps://github.com/dperson/torproxy. Refer toDockerfileanddocker-compose.yamlfor more details.dm@lnx:~/code/toripchanger$docker-composeup-dStarting toripchanger_tor-proxy_1 ... doneStarting toripchanger_tor-ip-changer_1 ... donedm@lnx:~/code/toripchanger$curlhttp://localhost:8080/changeip/{"error":"","newIp":"1.2.3.4"}UsageBasic examplesWith TorIpChanger you can define how often a Tor IP can be reused:fromtoripchangerimportTorIpChanger# Tor IP reuse is prohibited.tor_ip_changer_0=TorIpChanger(reuse_threshold=0)current_ip=tor_ip_changer_0.get_new_ip()# Current Tor IP address can be reused after one other IP was used (default setting).tor_ip_changer_1=TorIpChanger(local_http_proxy='127.0.0.1:8888')current_ip=tor_ip_changer_1.get_new_ip()# Current Tor IP address can be reused after 5 other Tor IPs were used.tor_ip_changer_5=TorIpChanger(tor_address="localhost",reuse_threshold=5)current_ip=tor_ip_changer_5.get_new_ip()Remote Tor controlSometimes, typically while using Docker, you may want to control a Tor instance
which doesn't run on localhost. To do this, you have two options.Use0.0.0.0as control addressSetControlPortto0.0.0.0:9051in yourtorrcfile  and settor_addresswhen initializing TorIpChangerfromtoripchangerimportTorIpChangertor_ip_changer=TorIpChanger(tor_address="172.17.0.2")current_ip=tor_ip_changer.get_new_ip()Though, Tor is not very happy about it (and rightly so) and will warn youYou have a ControlPort set to accept connections from a non-local address. This means that programs not running on your computer can reconfigure your Tor. That's pretty bad, since the controller protocol isn't encrypted! Maybe you should just listen on 127.0.0.1 and use a tool like stunnel or ssh to encrypt remote connections to your control port.Also, you have to set eitherCookieAuthenticationorHashedControlPasswordotherwiseControlPortwill be closedYou have a ControlPort set to accept unauthenticated connections from a non-local address. This means that programs not running on your computer can reconfigure your Tor, without even having to guess a password. That's so bad that I'm closing your ControlPort for you. If you need to control your Tor remotely, try enabling authentication and using a tool like stunnel or ssh to encrypt remote access.Please noteControlListenAddressconfig isOBSOLETEand Tor (tested with 0.3.3.7) will ignore it and log the following message[warn] Skipping obsolete configuration option 'ControlListenAddress'While the config itself is obsolte, itsdocumentation(not the official documentation!) concerning the risks related to exposingControlPorton0.0.0.0is still validWe strongly recommend that you leave this alone unless you know what you’re doing, since giving attackers access to your control listener is really dangerous.Usetoripchanger_servertoripchanger_serverscript starts a simple web server which allows you to change Tor' IP remotely using an HTTP get request to/changeip/. The response body is always{
    "newIp": "1.2.3.4",
    "error": ""
}with an appropriate status (erroris an empty string when all is good).Changing Tor' IP may not be instantaneous (especially when combined with a highreuse_threshold) and hence your client should use a reasonable timeout (e.g. at least 60s).toripchanger_servertakes all arguments required to initializeTorIpChangerplus--server-hostand--server-port, for more details see the usage below.usage: toripchanger_server [-h] [--server-host SERVER_HOST]
                           [--server-port SERVER_PORT]
                           [--reuse-threshold REUSE_THRESHOLD]
                           [--local-http-proxy LOCAL_HTTP_PROXY]
                           [--tor-password TOR_PASSWORD]
                           [--tor-address TOR_ADDRESS] [--tor-port TOR_PORT]
                           [--new-ip-max-attempts NEW_IP_MAX_ATTEMPTS]

optional arguments:
  -h, --help            show this help message and exit
  --server-host SERVER_HOST
                        TorIpChanger server host (default: 0.0.0.0)
  --server-port SERVER_PORT
                        TorIpChanger server port (default: 8080)
  --reuse-threshold REUSE_THRESHOLD
                        Number of IPs to use before reusing the current one
                        (default: 1)
  --local-http-proxy LOCAL_HTTP_PROXY
                        Local proxy IP and port (default: 127.0.0.1:8118)
  --tor-password TOR_PASSWORD
                        Tor controller password (default: "")
  --tor-address TOR_ADDRESS
                        IP address or resolvable hostname of the Tor
                        controller (default: 127.0.0.1)
  --tor-port TOR_PORT   Port number of the Tor controller (default: 9051)
  --new-ip-max-attempts NEW_IP_MAX_ATTEMPTS
                        Get new IP attempts limit (default: 10)To be able to change Tor IP remotely withtoripchanger_serverrunpip install toripchanger[server]in your containerstarttoripchanger_server(on the same host where Tor runs)expose the porttoripchanger_serverruns on to Docker host (or other containers)test changing IP works, e.g.curl http://localhost:8080/changeip/An exampledocker-compose.yamlcan be used for testing
as instructed in sectionDependencies.