我将 Tor 与 R 结合使用,并希望针对每个新请求更改我的 IP。我的代码如下:
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)
}
我可以通过 Tor 进行连接,但是标记为“不起作用”的两条线路似乎无法通过 Tor 获得正确的信号,因此 IP 保持不变。
Regards!
我遇到了类似的问题,但在将 Privoxy 安装为 http 代理并按说明进行设置后设法使其工作here http://www.privoxy.org/faq/misc.html#TOR。然后,这是我在 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,身份验证方法为“密码”,将上面代码中双引号之间的密码替换为您设置的密码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)