改变R中的Tor身份 [英] Changing Tor identity in R

查看:618
本文介绍了改变R中的Tor身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Tor与R结合使用,并希望为每个新请求更改我的IP。我的代码如下:

I am using Tor in combination with R and would like to change my IP for each new request. The code I have is as follows:

library(RCurl)
opts <- list(proxy="127.0.0.1", proxyport=8118)
for (i in 1:10)
  {
  con <- socketConnection(host="127.0.0.1",port=9051)  # DOES NOT WORK
  writeLines("signal newnym", con=con)                 # DOES NOT WORK
  ip <- getURL("http://ifconfig.me/ip", .opts = opts)  
  print(ip)
  Sys.sleep(1)
  }  

I我能够通过Tor连接,但标记为DOES NOT WORK的两条线似乎没有得到正确的信号到Tor,所以IP保持不变。

I am able to connect via Tor, however the two lines marked as 'DOES NOT WORK' don't seem to get the proper signal across to Tor, so the IP stays the same.

问候!

推荐答案

我遇到了类似的问题,但在将Privoxy作为http代理安装后设法使其工作正常按照此处的说明进行设置。然后,这是我在R中使用的代码:

I had a similar problem, but managed to make it work after installing Privoxy as a http-proxy and setting it up as explained here. Then, this is the code I used in R:

library(RCurl)
# check current IP address
print(getURL("http://ifconfig.me/ip"))
# proxy options
opts <- list(proxy="127.0.0.1", proxyport=8118)
# opening connection with TOR
con <- socketConnection(host="127.0.0.1",port=9051)
print(getURL("http://ifconfig.me/ip", .opts = opts))  

for (i in 1:10)
    {
    writeLines('AUTHENTICATE \"password\"\r\nSIGNAL NEWNYM\r\n', con=con)
    Sys.sleep(5)
    print(getURL("http://ifconfig.me/ip", .opts = opts)) 
    Sys.sleep(5)
    }  

确保使用TCP的手动设置连接,地址127.0.0.1:9051,验证方法为password,用上面代码中的双引号代替你设置的密码。

Make sure you are using manual settings for the TCP connection, with address 127.0.0.1:9051, and the authentication method is "password", substituting the password between double quotes in the code above with the one you set.

这篇关于改变R中的Tor身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆