dperson / torproxy

GNU Affero General Public License v3.0
520 stars 146 forks source link

Generate new circuit every n minutes? #80

Open tamis-laan opened 2 years ago

tamis-laan commented 2 years ago

It would be great if there was a setting where torproxy would generate a new circuit every n minutes. This to cycle the ip address of the exit node.

des1redState commented 1 year ago

You'd need a script to send the NEWNYM signal to the Tor process every n minutes. Python example:

#!/usr/bin/env python

from time import sleep
from stem import Signal
from stem.control import Controller

n = "10m"  # or whatever's desired.
tor_control_port = 9051  # Ensure this is exposed (e.g: -p 9051:9051)
tor_control_pass = "password"  # Default, might want to change it. See docs.

while True:
    with Controller.from_port(port=tor_control_port) as c:
        c.authenticate(password=tor_control_pass)
        c.signal(Signal.NEWNYM)

    sleep(n)
byteofwood commented 1 year ago

You could also do this as a shell command. Bash one-liner: while :; do printf 'AUTHENTICATE "YourPassword"\r\nSIGNAL NEWNYM\r\n' | ncat 0.0.0.0 9051; sleep 600; done

DailyPS commented 3 months ago

@des1redState @byteofwood I wonder how above script works.

Using image of this repository also works? For example:

I use dperson/torproxy image with depends_on on other container like below.

services:
  simple_continer:
    image: example:latest
    depends_on:
      -torproxy
  torproxy:
    image: dperson/torproxy
    ports:
      - "8118:8118"

If I want to generate new circuit every n minutes using a python script or a shell script, how should I work with it?

Or should I clone this repository and revise torproxy.sh?