Changing Tor identity in R

前端 未结 1 2075
轮回少年
轮回少年 2021-02-01 05:59

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=\"1         


        
1条回答
  •  不思量自难忘°
    2021-02-01 06:20

    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.

    0 讨论(0)
提交回复
热议问题