教程"与俄罗斯交谈"停留在45-50%

时间:2015-04-26 11:00:54

标签: python-2.7 tor

当我尝试按照教程(https://stem.torproject.org/tutorials/to_russia_with_love.html)关于如何启动Tor时,我一直停留在45%,有时达到50%。我使用的是Windows 8,python 3.4和LiClipse ide。

  

[1m启动Tor:[0m [34mApr 26 12:47:21.000 [通知]自举   0%:开始[0m [34mApr 26 12:47:21.000 [通知]自举45%:   要求中继描述符[0m   [34mApr 26 13:04:00.000 [通知]自举50%:加载中继描述符[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%。< / p>

另外,如果我停止了Tor.exe进程,当它停留在45%时就会告诉我:

  

回溯(最近一次呼叫最后一次):文件&#34; C:\ Users \ gatsu \ My   Documents \ LiClipse Workspace \ TorCommunicator \ TorConnector.py&#34;,line   53,在       init_msg_handler = print_bootstrap_lines,File&#34; C:\ Python34 \ lib \ site-packages \ stem \ process.py&#34;,第246行,in   launch_tor_with_config       return launch_tor(tor_cmd,args,torrc_path,completion_percent,init_msg_handler,timeout,take_ownership)文件   &#34; C:\ Python34 \ lib \ site-packages \ stem \ process.py&#34;,第136行,in   launch_tor       引发OSError(&#39;进程终止:%s&#39;%last_problem)OSError:进程终止:无法打开GEOIP文件   C:\ Users \用户gatsu \应用程序数据\漫游\ TOR \ geoip6。我们已配置为   在某些国家使用(或避免)节点,我们需要GEOIP   信息,以确定它们是谁。

我希望能弄清楚为什么这会让我陷入困境。

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

3 个答案:

答案 0 :(得分:2)

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

  

[1m开始Tor:[0m [34mMay 01 23:28:53.000 [notice] Bootstrapped   0%:开始[0m [34mMay 01 23:28:53.000 [notice] Bootstrapped 80%:   连接到Tor网络[0m [34may 01 23:28:54.000 [通知]   自举85%:与第一跳完成握手[0m [34mMay 01   23:28:54.000 [通知]自举90%:建立Tor电路[0m   [34mMay 01 23:28:55.000 [通知] 100%自举:完成[0m [1m]   检查我们的终点:[0m [34m无法到达   https://www.atagar.com/echo.php [0米

答案 1 :(得分:2)

answer provided by @Alter相关。 在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,
)

答案 2 :(得分:1)

或者,您可以通过将geoip和geoipv6传递到配置中来指定当前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,
)

作为旁注,如果您有此错误。在运行另一个(在Windows中,进入任务管理器并查找/终止)之前,您需要杀死停留在45%的TOR进程(&#39;