我正在使用连接到tor网络的干线示例,这应该将客户端连接到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都好的电路,但看起来虽然它没有使用它?
我在这里排在正确的位置?
谢谢你们
答案 0 :(得分:1)
您必须将浏览器设置为使用 Tor 作为代理。
如果您使用 Firefox :
转到修改,偏好设置,高级,然后选择"配置firefox连接到互联网的方式"的设置
在 socks主机中输入127.0.0.1
,在端口下输入 7000 。
转到whatismyip.com,您将看到一个新的IP。 或check tor,project看到您成功使用 Tor 。