tor 教程 "speaking to russia" 停留在 45 - 50%

tor tutorial "speaking to russia" stuck at 45 - 50%

当我尝试按照有关如何启动 Tor 的教程 (https://stem.torproject.org/tutorials/to_russia_with_love.html) 进行操作时,我一直卡在 45%,有时 卡在 50%。我正在使用 windows 8、python 3.4 和 LiClipse ide.

[1mStarting Tor: [0m [34mApr 26 12:47:21.000 [notice] Bootstrapped 0%: Starting[0m [34mApr 26 12:47:21.000 [notice] Bootstrapped 45%: Asking for relay descriptors[0m [34mApr 26 13:04:00.000 [notice] Bootstrapped 50%: Loading relay descriptors[0m

脚本看起来像这样,我在这里所做的更改是使用 requests 库而不是 urllib 从源请求数据,但我没有到达那部分无论如何这里的代码。这基本上是教程页面上使用 SocksiPy 的代码副本。

TorConnector.py:

from io import StringIO
import socket
import requests

import socks  # SocksiPy module
import 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 requests to fetch a site using SocksiPy for Tor over the SOCKS_PORT.
  """

  try:
    result = requests.get(url)
    return result
  except:
    return "Unable to reach %s" % url



# Start an instance of Tor configured to only exit through Russia. This prints
# Tor's bootstrap information as it starts. Note that this likely will not
# work if you have another Tor instance running.

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(
  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()  # stops tor

我也尝试过将 TorConnector.py 脚本文件移动到 C:\Python34\Lib\site-packages 文件夹中,然后 运行 从带有 python TorConnector.py 的命令提示符中移动它,但同样的事情发生了,我我仍然停留在 45%。

此外,如果我在进程卡在 45% 时结束 Tor.exe 进程,它会告诉我:

Traceback (most recent call last): File "C:\Users\gatsu\My Documents\LiClipse Workspace\TorCommunicator\TorConnector.py", line 53, in init_msg_handler = print_bootstrap_lines, File "C:\Python34\lib\site-packages\stem\process.py", line 246, in launch_tor_with_config return launch_tor(tor_cmd, args, torrc_path, completion_percent, init_msg_handler, timeout, take_ownership) File "C:\Python34\lib\site-packages\stem\process.py", line 136, in launch_tor raise OSError('Process terminated: %s' % last_problem) OSError: Process terminated: Failed to open GEOIP file C:\Users\gatsu\AppData\Roaming\tor\geoip6. We've been configured to use (or avoid) nodes in certain countries, and we need GEOIP information to figure out which ones they are.

我希望这有助于弄清楚为什么这让我陷入困境。

我什至没有这个文件:C:\Users\gatsu\AppData\Roaming\tor\geoip6

我在tor浏览器文件夹(D:\Program\Tor Browser\Browser\TorBrowser\Data\Tor)中找到了geoipgeoip6文件,并将它们复制到C:\Users\gatsu\AppData\Roaming\tor这让我达到了 100%。

[1mStarting Tor: [0m [34mMay 01 23:28:53.000 [notice] Bootstrapped 0%: Starting[0m [34mMay 01 23:28:53.000 [notice] Bootstrapped 80%: Connecting to the Tor network[0m [34mMay 01 23:28:54.000 [notice] Bootstrapped 85%: Finishing handshake with first hop[0m [34mMay 01 23:28:54.000 [notice] Bootstrapped 90%: Establishing a Tor circuit[0m [34mMay 01 23:28:55.000 [notice] Bootstrapped 100%: Done[0m [1m Checking our endpoint: [0m [34mUnable to reach https://www.atagar.com/echo.php[0m

或者,您可以通过将 geoip 和 geoipv6 传递到您的配置中来指定当前位置。有关配置选项的完整列表,请参阅 TOR manual

tor_process = stem.process.launch_tor_with_config(
  config = {
    'SocksPort': str(SOCKS_PORT),
    'ExitNodes': '{ru}',
    'GeoIPFile': r'C:\Program Files (x86)\tor-win32-0.2.8.9\Data\Tor\geoip',
    'GeoIPv6File' : r'C:\Program Files (x86)\tor-win32-0.2.8.9\Data\Tor\geoip6'
  },
  init_msg_handler = print_bootstrap_lines,
)

作为旁注,如果您遇到此错误。您需要先终止卡在 45% 的 TOR 进程,然后再 运行 另一个(在 windows 中,进入任务管理器并 find/kill 'tor)'

相关。 在 MacOs Sierra 中,一个有效的 tor_process 配置(解决这个问题)是

tor_process = stem.process.launch_tor_with_config(
    tor_cmd = '/Applications/TorBrowser.app/Contents/MacOS/Tor/tor.real',
    config = {
        'SocksPort': str(SOCKS_PORT),
        'ExitNodes': '{ru}',
        'GeoIPFile': r'/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/geoip',
        'GeoIPv6File' : r'/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/geoip6'
    },
    init_msg_handler = print_bootstrap_lines,
)