python - Stem 不会在 Python 中生成新的 IP 地址

标签 python tor

为什么 Signal.NEWNYM 没有生成新的 IP 地址?

from stem import Signal
from stem.control import Controller
import requests

with Controller.from_port(port=9051) as controller:
    print('Ready')
    controller.authenticate(password='872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C')
    print("Success!")
    controller.signal(Signal.NEWNYM)
    print("New Tor connection processed")
    print(requests.get('http://icanhazip.com').content)

最佳答案

NEWNYM 信号并不用于获取新的导出节点,它只是将当前电路标记为脏并确保新连接将使用新电路。

来自 stem docs :

An important thing to note is that a new circuit does not necessarily mean a new IP address. Paths are randomly selected based on heuristics like speed and stability. There are only so many large exits in the Tor network, so it's not uncommon to reuse an exit you have had previously.

Tor does not have a method for cycling your IP address. This is on purpose, and done for a couple reasons. The first is that this capability is usually requested for not-so-nice reasons such as ban evasion or SEO. Second, repeated circuit creation puts a very high load on the Tor network, so please don't!

编辑。我最初错过了您在提出请求时没有使用 Tor(代理)!这是问题的第一部分。

您应该首先安装对 requests 库的 socks 支持 (pip install requests[socks]),然后通过本地 Tor 代理发出请求,像这样:

requests.get('https://httpbin.org/ip', 
             proxies={'http': 'socks5://127.0.0.1:9050',
                      'https': 'socks5://127.0.0.1:9050'}).text

关于python - Stem 不会在 Python 中生成新的 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45092345/

相关文章:

python - scipy中的简单计算: minima

python - 闲置一段时间后的性能

python - 库未在 Python (pygame) 中初始化

python - HTMLParseError : unknown status keyword u'cadta' in marked section, 位于第 1 行第 54 列

linux - 如何使用不同的导出 IP 一次运行多个 Tor 进程?

nginx - 如何创建 .onion 网站?

Python-文本挖掘-TypeError : __hash__ method should return an integer

Scrapy Torproject

python - 有没有办法在Linux中通过Python启用tor作为系统代理设置

tor - 如何在 TOR (windows) 上指定 IP 国家/地区?