tor: use random credentials for circuit isolation
This commit is contained in:
12
fetch.py
12
fetch.py
@@ -1,4 +1,4 @@
|
||||
import re, random, time
|
||||
import re, random, time, string
|
||||
import threading
|
||||
import rocksock
|
||||
import network_stats
|
||||
@@ -7,6 +7,14 @@ from soup_parser import soupify
|
||||
from misc import _log
|
||||
|
||||
config = None
|
||||
|
||||
|
||||
def tor_proxy_url(torhost):
|
||||
"""Generate Tor SOCKS5 proxy URL with random credentials for circuit isolation."""
|
||||
chars = string.ascii_lowercase + string.digits
|
||||
user = ''.join(random.choice(chars) for _ in range(8))
|
||||
passwd = ''.join(random.choice(chars) for _ in range(8))
|
||||
return 'socks5://%s:%s@%s' % (user, passwd, torhost)
|
||||
_last_fail_log = 0
|
||||
_fail_log_interval = 60
|
||||
|
||||
@@ -58,7 +66,7 @@ def _fetch_contents(url, head = False, proxy=None):
|
||||
http = None
|
||||
try:
|
||||
while True:
|
||||
proxies = [rocksock.RocksockProxyFromURL('socks4://%s' % random.choice( config.torhosts ))]
|
||||
proxies = [rocksock.RocksockProxyFromURL(tor_proxy_url(random.choice(config.torhosts)))]
|
||||
if proxy: proxies.append( rocksock.RocksockProxyFromURL(proxy))
|
||||
|
||||
http = RsHttp(host,ssl=ssl,port=port, keep_alive=True, timeout=config.ppf.timeout, max_tries=config.ppf.http_retries, follow_redirects=True, auto_set_cookies=True, proxies=proxies, user_agent='Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0', log_errors=False)
|
||||
|
||||
Reference in New Issue
Block a user