我正在使用连接到 tor 网络的 stem 示例,这应该将客户端连接到 tor 网络,它似乎正在这样做但是当我检查 ip 地址时它是不正确的而不是 tor ip,任何关于为什么会这样,更重要的是我该如何解决这个问题的想法:)
import StringIO
import socket
import urllib
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 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
# 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,
)
我得到输出:
richard@Tornado:~/Documents/Masters Project$ python russiaExample.py
Starting Tor:
May 26 21:56:49.000 [notice] Bootstrapped 80%: Connecting to the Tor network.
May 26 21:56:50.000 [notice] Bootstrapped 85%: Finishing handshake with first hop.
May 26 21:56:50.000 [notice] Bootstrapped 90%: Establishing a Tor circuit.
May 26 21:56:50.000 [notice] Bootstrapped 100%: Done.
然而当我访问https://check.torproject.org/检查我正在使用 tor,它说我现在,并且显示了我的正常 ip,
是什么导致了这个问题,因为上面显示的输出似乎表明它已经建立了一个对 Tor 来说一切正常的电路,但似乎它没有使用它?
我在这里的路线正确吗?
谢谢大家
请您参考如下方法:
您必须将浏览器设置为使用 Tor 作为代理。
如果您使用的是 Firefox:
转到编辑、首选项、高级并选择“配置 firefox 连接到互联网的方式”设置.
在 socks host 中输入
127.0.0.1并在 port 下输入 7000。
转到 whatismyip.com你会看到一个新的 ip。 或者 check tor,project查看您是否正在成功使用 Tor。
