Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Tor identity in R

Tags:

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!

like image 865
blaster Avatar asked Jun 18 '12 19:06

blaster


1 Answers

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.

like image 118
Pablo Barbera Avatar answered Nov 15 '22 11:11

Pablo Barbera