gpt4 book ai didi

python - tor 通过 python - 连接正常,但没有出现在 tor 上

转载 作者:太空宇宙 更新时间:2023-11-04 06:02:50 25 4
gpt4 key购买 nike

我正在使用连接到 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:

  1. 转到编辑首选项高级并选择“配置 firefox 连接到互联网的方式”设置.

  2. socks host 中输入 127.0.0.1 并在 port 下输入 7000

转到 whatismyip.com你会看到一个新的 ip。或者 check tor,project查看您是否正在成功使用 Tor

关于python - tor 通过 python - 连接正常,但没有出现在 tor 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23877698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com