python - 在python中获取新的IP

标签 python tor

我目前正在尝试通过 python 获取新的 IP。

我在 stackoverflow 上找到了这个脚本:

import urllib2
from TorCtl import TorCtl

proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})
opener = urllib2.build_opener(proxy_support) 

def newId():
    conn = TorCtl.connect(controlAddr="127.0.0.1", controlPort=9051, passphrase="123")
    conn.send_signal("NEWNYM")

for i in range(0, 10):
    print "case "+str(i+1)
    newId()
    proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})
    urllib2.install_opener(opener)
    print(urllib2.urlopen("http://www.ifconfig.me/ip").read())

我正在运行 vidalia 和 privoxy。我的设置正确:

在系统偏好设置中(在 Mac 上):

网络代理 (HTTP):127.0.0.1:8118 HTTPS 也是如此

在我的 privoxy 配置文件中,我有这一行:

 forward-socks5   /               127.0.0.1:9051 .

在我的 vidalia 设置中:

Image

尽管当我运行代码时,它仍然停留在情况 1 上,并且我无法获取 IP。 这是我的 vidalia 日志:

May 04 19:15:27.381 [Notice] New control connection opened.
May 04 19:15:27.382 [Notice] New control connection opened.
May 04 19:15:33.709 [Notice] New control connection opened.
May 04 19:15:38.653 [Notice] New control connection opened.
May 04 19:15:57.382 [Notice] New control connection opened.
May 04 19:15:57.463 [Notice] New control connection opened.
May 04 19:15:57.464 [Notice] New control connection opened.
May 04 19:16:03.710 [Notice] New control connection opened.
May 04 19:16:19.656 [Notice] New control connection opened.
May 04 19:16:22.448 [Notice] New control connection opened.
May 04 19:16:22.569 [Notice] New control connection opened.
May 04 19:16:22.900 [Notice] New control connection opened.
May 04 19:16:27.382 [Notice] New control connection opened.
May 04 19:16:27.412 [Notice] New control connection opened.
May 04 19:16:27.413 [Notice] New control connection opened.

我做错了什么?

编辑:

当配置文件中的行处于事件状态时,我无法加载任何站点。

显然,如果我等待足够长的时间,就会收到错误:

urllib2.HTTPError: HTTP Error 503: Forwarding failure

最佳答案

forward-socks5   /               127.0.0.1:9050 .

不是

forward-socks5   /               127.0.0.1:9051 .

关于python - 在python中获取新的IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16376987/

相关文章:

nginx - 如何使 nginx 反向代理直接到 tor 隐藏服务?

python - 处理仅在启动后立即出现的错误

python - 模型字段 "verbose name"的使用

python - 如何在python中正确处理多个二进制文件?

c# - 使用 IronPython 通过 C# .NET 导入 Python 模块

tor - 无法创建单跳电路(单跳隧道)

node.js - 问 : Hot to change Ip in request using tor-request npm

python - 如何统计Python中某个单词出现的次数

c# - 使用 Puppeteer-sharp 启动 Tor 浏览器

tcp - 如何通过 vidalia tor 重定向 Windows 中的所有流量?