【问题标题】:Stem as python tor client - stuck on loading descriptorsStem 作为 python tor 客户端 - 卡在加载描述符上
【发布时间】:2023-04-02 18:26:01
【问题描述】:

我正在尝试使用 python stem 连接到 tor,同时尝试连接(使用修改后的示例)它只是无法正常工作......这是我的代码:
(我使用的是 python 3.4.1)

import socket,urllib, sys, socks, stem.process
from stem.util import term    

SOCKS_PORT = 7000

# Set socks proxy and wrap the urllib module

socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', SOCKS_PORT) socket.socket = socks.socksocket

# Perform DNS resolution through the socket

def getaddrinfo(*args):   return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))]

socket.getaddrinfo = getaddrinfo


def query(url):   """   Uses urllib to fetch a site using SocksiPy for Tor over the SOCKS_PORT.   """

  try:
    return urllib.urlopen(url).read()   except:
    return "Unable to reach %s" % url



def print_bootstrap_lines(line):   if "Bootstrapped " in line:
      print(term.format(line, term.Color.BLUE))


print(term.format("Starting Tor:\n", term.Attr.BOLD))

tor_process = stem.process.launch_tor_with_config(   tor_cmd = "C:\Users\Nadav\Desktop\Tor Browser\Tor\\tor.exe" ,   config = {
    'SocksPort': str(SOCKS_PORT),
    'ExitNodes': '{ru}',   },   init_msg_handler = print_bootstrap_lines, )

print(term.format("\nChecking our endpoint:\n", term.Attr.BOLD)) print(term.format(query("https://www.atagar.com/echo.php"), term.Color.BLUE))

tor_process.kill

【问题讨论】:

    标签:
    python
    proxy
    tor