您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在Python中更改Tor身份?

如何在Python中更改Tor身份?

今天,我对这个问题进行了很多搜索,最后设法回答了自己。但是在我不得不说pirvoxy和tor应该正确配置之前。第一个脚本,然后是一些配置:

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="your_password")
    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())

上面的脚本获取了新的IP并从ifconfig.me网站进行了检查。关于配置:我们需要Privoxy。要将TOR与HTTP连接一起使用,privoxy应该与tor一起使用。我们可以通过在/ etc / privoxy / config文件添加thi来做到这一点:

forward-socks5 / localhost:9050 . #dot is important at the end

然后在/ etc / tor / torrc文件中配置ControlPort。我们只需要取消以下行的注释:

ControlPort 9051
## If you enable the controlport, be sure to enable one of these
## authentication methods, to prevent attackers from accessing it.
HashedControlPassword 16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C

然后我们重新启动tor:

/etc/init.d/tor restart
python 2022/1/1 18:44:29 有287人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶