I have a python script which uses Tor as SOCKS proxy.
I would like to change Tor's exit node only by script, I mean Tor shouldn't change exit node by itself.
How I change exit node when needed by the script:
from stem import Signal
from stem.control import Controller
with Controller.from_port(port = 9051) as controller:
controller.authenticate()
controller.signal(Signal.NEWNYM)
How I periodically check which ip has my exit node:
import re
import requests
response = requests.get('https://check.torproject.org/')
if response.status_code == 200:
match = re.search(r'([0-9]{1,3}.){3}[0-9]{1,3}', response.text)
if match:
return match.group(0)
My torrc file:
SOCKSPort 9050
SocksBindAddress 127.0.0.1
MaxCircuitDirtiness 86400 # == a day
DataDirectory $a_dir_in_my_home
ControlPort 9051
HashedControlPassword $my_hased_password
How I run Tor:
tor -f $my_torrc_file
But unfortunately by the logs of the script I can see that sometimes (more than 10 in an hour) the exit node changes unexpectedly.
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire