Ruby、Tor 和 Net::HTTP::Proxy [英] Ruby, Tor and Net::HTTP::Proxy

查看:65
本文介绍了Ruby、Tor 和 Net::HTTP::Proxy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是一个小白疑问,我提前道歉:我想在我的 Ruby 代码中使用代理来获取一些网页.我想偷偷摸摸!所以我使用 Tor.

My apologies in advance if this is a noobish doubt: I want to use a proxy in my Ruby code to fetch a few web pages. And I want to be sneaky about it! So I am using Tor.

我有 Tor 运行,我可以像往常一样使用 Net::HTTP.get(uri).但我不知道如何使用 Net::HTTP::Proxy 来获取 uri.我也无法弄清楚使用 Tor 将如何帮助使我的提取匿名.

I have Tor running, and I am able to use Net::HTTP.get(uri) as usual. But I can't figure out how to use Net::HTTP::Proxy to fetch the uri. I also can't figure out how using Tor will help make my fetches anonymous.

非常感谢任何帮助.请不要只添加 链接到 Net::HTTP::Proxy 的 ruby​​-doc 页面.如果我明白这一点,我就不会在这里问这个了:-)

Any help is greatly appreciated. Please don't just add a link to the ruby-doc page for Net::HTTP::Proxy. If I had understood that, I would not be asking this here :-)

另一种简单的方法是使用 SOCKSify,但在这种情况下,我收到以下错误:

Another easy way to do this is using SOCKSify, but in this case, I receive the following error:

/usr/lib/ruby/gems/1.9.2-p290/gems/socksify-1.5.0/lib/socksify.rb:189:in 'socks_authenticate': 不支持 SOCKS 版本 (SOCKSError)

我以前从未做过任何网络编程.任何有关这方面的指导也将非常有帮助.谢谢:-)

I have never done any network programming before. Any guidance about this will also be very helpful. Thanks :-)

推荐答案

您使用的是 HTTP 代理类,因此您必须提供 HTTP 代理的 IP.Tor 浏览器没有捆绑了 HTTP 代理.

You are using HTTP proxy class, so you must provide IP of HTTP proxy. Tor Browser has not HTTP proxy bundled.

所以你可以安装一些代理软件,例如Privoxy 并将其配置为使用 Tor 的 SOCKS:

So you can either install some proxy software e.g. Privoxy and configure it to use Tor's SOCKS:

config.txtforward-socks4a/127.0.0.1:9050 .

然后在脚本中使用 Privoxy 的默认listen-address:

then use Privoxy's default listen-address in your script:

proxy = Net::HTTP::Proxy('127.0.0.1',8118)

使用 SOCKSify.根据文档:

or use SOCKSify. According to docs:

require 'socksify/http'
uri = URI.parse('http://rubyforge.org/')
Net::HTTP.SOCKSProxy('127.0.0.1', 9050).start(uri.host, uri.port) do |http|
  http.get(uri.path)
end

不需要额外的软件..

第三种解决方案是使用SOCKSify如下:

Third solution is to use SOCKSify as follows:

$ socksify_ruby localhost 9050 script.rb

重定向 Ruby 脚本的所有 TCP 连接,这意味着您根本不需要使用任何代理代码.

which redirect all TCP connections of a Ruby script, which means you don't need to use any Proxy code at all.

为了澄清起见,您必须了解 127.0.0.1:9050 是 Tor 的 SOCKS 地址,而 127.0.0.1:8118 是 Privoxy 的地址.

这篇关于Ruby、Tor 和 Net::HTTP::Proxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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