gpt4 book ai didi

python - 仅通过标准 python 套接字获取 Tor7.0 的新 IP

转载 作者:太空宇宙 更新时间:2023-11-03 15:07:33 24 4
gpt4 key购买 nike

当我尝试在 Windows 10 上更新 Tor 的 IP 时,它总是失败(我读了很多堆栈溢出的帖子,如 thisthis ,但没有任何效果)。

  • 操作系统:Windows 10 64位
  • tor:版本7.0

我的torrc的内容

# This file was generated by Tor; if you edit it, comments will not be preserved
# The old torrc file was renamed to torrc.orig.1 or similar, and Tor will ignore it

DataDirectory C:\Users\yyyy\Desktop\Tor Browser\Browser\TorBrowser\Data\Tor
GeoIPFile C:\Users\yyyy\Desktop\Tor Browser\Browser\TorBrowser\Data\Tor\geoip
GeoIPv6File C:\Users\yyyy\Desktop\Tor Browser\Browser\TorBrowser\Data\Tor\geoip6
HiddenServiceStatistics 0

HashedControlPassword 16:D14CC89AD7848B8C60093105E8284A2D3AB2CF3C20D95FECA0848CFAD2
CookieAuthentication 1 #either with nor without this line, still fail

torrc-defaults 的内容

# torrc-defaults for Tor Browser
#
# DO NOT EDIT THIS FILE
#
# This file is distributed with Tor Browser and SHOULD NOT be modified (it
# may be overwritten during the next Tor Browser update). To customize your
# Tor configuration, shut down Tor Browser and edit the torrc file.
#
# If non-zero, try to write to disk less frequently than we would otherwise.
AvoidDiskWrites 1
# Where to send logging messages. Format is minSeverity[-maxSeverity]
# (stderr|stdout|syslog|file FILENAME).
Log notice stdout
CookieAuthentication 1
## fteproxy configuration
ClientTransportPlugin fte exec TorBrowser\Tor\PluggableTransports\fteproxy --managed

## obfs4proxy configuration
ClientTransportPlugin obfs2,obfs3,obfs4,scramblesuit exec TorBrowser\Tor\PluggableTransports\obfs4proxy

## meek configuration
ClientTransportPlugin meek exec TorBrowser\Tor\PluggableTransports\terminateprocess-buffer TorBrowser\Tor\PluggableTransports\meek-client-torbrowser -- TorBrowser\Tor\PluggableTransports\meek-client

用于更新tor ip的脚本

import repr as reprlib
import socket
import sys

try:
tor_c = socket.create_connection(("127.0.0.1", 9151))
tor_c.send('AUTHENTICATE "{}"\r\n'.format("16:D14CC89AD7848B8C60093105E8284A2D3AB2CF3C20D95FECA0848CFAD2"))
response = tor_c.recv(1024)
if response != '250 OK\r\n250 OK\r\n':
sys.stderr.write('Unexpected response from Tor control port: {}\n'.format(response))
except Exception, e:
sys.stderr.write('Error connecting to Tor control port: {}\n'.format(repr(e)))

但服务器总是回复我

来自 Tor 控制端口的意外响应:515 身份验证失败:密码与 HashedControlPassword 不匹配身份验证 cookie。

我知道有用于此类任务的Python库,但我想仅通过Python的标准套接字库更新IP,我该如何正确执行此操作?谢谢

最佳答案

HashedControlPassword是身份验证密码的哈希值。要进行身份验证,请使用AUTHENTICATE“您的实际密码”

控制协议(protocol)表面上比较简单。

例如:

telnet localhost 9051
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
authenticate "password"
250 OK
signal NEWNYM
250 OK <-- identity changed for new circuits

这对我有用:

import repr as reprlib
import socket
import sys

try:
tor_c = socket.create_connection(("127.0.0.1", 9051))
tor_c.send("AUTHENTICATE \"{}\"\n".format("password"))
response = tor_c.recv(1024)
if response != '250 OK\r\n':
sys.stderr.write('Unexpected response from Tor control port: {}\n'.format(response))
tor_c.send("SIGNAL NEWNYM\n");
response = tor_c.recv(1024)
print(response)
except Exception, e:
sys.stderr.write('Error connecting to Tor control port: {}\n'.format(repr(e)))

您还可以按照以下示例来避免使用 Python:Request new identity from Windows command line .

关于python - 仅通过标准 python 套接字获取 Tor7.0 的新 IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44517599/

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