Код: Выделить всё
Error renewing Tor IP: [WinError 10061] No connection could be made because the target computer actively refused it
Код: Выделить всё
import subprocess # Import subprocess module for starting Tor
from stem import Signal
from stem.control import Controller
import requests
import shutil
import os
import time
import sys
def start_tor():
try:
tor_path = r"C:\Users\anjoyer\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe"
subprocess.Popen([tor_path])
print("Tor started successfully.")
time.sleep(5) # Give Tor some time to start up (adjust as needed)
except Exception as e:
print(f"Error starting Tor: {e}")
def renew_tor_ip():
try:
with Controller.from_port(port=9051) as controller:
controller.authenticate(password='HashedControlPassword')
controller.signal(Signal.NEWNYM)
print("Tor IP renewed successfully.")
except Exception as e:
print(f"Error renewing Tor IP: {e}")
proxies = {
'http': 'socks5h://127.0.0.1:9050',
'https': 'socks5h://127.0.0.1:9050'
}
def get_new_ip():
renew_tor_ip()
response = requests.get('http://httpbin.org/ip', proxies=proxies)
return response.json()
if __name__ == "__main__":
start_tor() # Start Tor
renew_tor_ip()
while True:
time.sleep(300)
renew_tor_ip()
Код: Выделить всё
ControlPort 9051
HashedControlPassword HashedControlPassword
Код: Выделить всё
Tor started successfully.
Jun 23 19:25:59.793 [notice] Tor 0.4.8.12 (git-2beaa7557c3c93ec) running on Windows 8 [or later] with Libevent 2.1.12-stable, OpenSSL 3.0.14, Zlib 1.3.1, Liblzma N/A, Libzstd N/A and Unknown N/A as libc.
Jun 23 19:25:59.793 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://support.torproject.org/faq/staying-anonymous/
Jun 23 19:25:59.801 [notice] Configuration file "C:\Users\anjoyer\AppData\Roaming\tor\torrc" not present, using reasonable defaults.
Jun 23 19:25:59.801 [warn] Path for GeoIPFile () is relative and will resolve to C:\Users\anjoyer\desktop\. Is this what you wanted?
Jun 23 19:25:59.801 [warn] Path for GeoIPv6File () is relative and will resolve to C:\Users\anjoyer\desktop\. Is this what you wanted?
Jun 23 19:25:59.803 [notice] Opening Socks listener on 127.0.0.1:9050
Jun 23 19:25:59.803 [notice] Opened Socks listener connection (ready) on 127.0.0.1:9050
Jun 23 19:25:59.000 [notice] Bootstrapped 0% (starting): Starting
Jun 23 19:26:00.000 [notice] Starting with guard context "default"
Jun 23 19:26:01.000 [notice] Bootstrapped 5% (conn): Connecting to a relay
Jun 23 19:26:01.000 [notice] Bootstrapped 10% (conn_done): Connected to a relay
Jun 23 19:26:01.000 [notice] Bootstrapped 14% (handshake): Handshaking with a relay
Jun 23 19:26:02.000 [notice] Bootstrapped 15% (handshake_done): Handshake with a relay done
Jun 23 19:26:02.000 [notice] Bootstrapped 75% (enough_dirinfo): Loaded enough directory info to build circuits
Jun 23 19:26:02.000 [notice] Bootstrapped 90% (ap_handshake_done): Handshake finished with a relay to build circuits
Jun 23 19:26:02.000 [notice] Bootstrapped 95% (circuit_create): Establishing a Tor circuit
Jun 23 19:26:03.000 [notice] Bootstrapped 100% (done): Done
Error renewing Tor IP: [WinError 10061] No connection could be made because the target computer actively refused it
Я запустил Tor вручную и убедился, что он работает.
Я проверил настройки брандмауэра. чтобы убедиться, что Tor имеет разрешения на порт 9051 и tor.exe.
Подробнее здесь: https://stackoverflow.com/questions/786 ... em-library