Changing Tor identity in R

风格不统一 提交于 2019-12-20 09:35:57

问题


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 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.

Regards!


回答1:


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)
    }  

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.



来源:https://stackoverflow.com/questions/11089993/changing-tor-identity-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!