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.
如果这是一个无耻的怀疑我提前道歉:我想在我的Ruby代码中使用代理来获取一些网页。而且我想偷偷摸摸!所以我正在使用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.
我有Tor运行,我可以像往常一样使用Net :: HTTP.get(uri)。但我无法弄清楚如何使用Net :: HTTP :: Proxy来获取uri。我也无法弄清楚如何使用Tor来帮助我取消匿名。
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 :-)
任何帮助是极大的赞赏。请不要只为Net :: HTTP :: Proxy添加ruby-doc页面的链接。如果我明白了,我不会在这里问这个:-)
Another easy way to do this is using SOCKSify, but in this case, I receive the following error:
另一种简单的方法是使用SOCKSify,但在这种情况下,我收到以下错误:
/usr/lib/ruby/gems/1.9.2-p290/gems/socksify-1.5.0/lib/socksify.rb:189:in 'socks_authenticate': SOCKS version not supported (SOCKSError)
/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 :-)
我之前从未做过任何网络编程。任何关于此的指导也将非常有帮助。谢谢 :-)
1 个解决方案
#1
14
You are using HTTP proxy class, so you must provide IP of HTTP proxy. Tor Browser has not HTTP proxy bundled.
您正在使用HTTP代理类,因此您必须提供HTTP代理的IP。 Tor Browser没有绑定HTTP代理。
So you can either install some proxy software e.g. Privoxy and configure it to use Tor's SOCKS:
所以你可以安装一些代理软件,例如Privoxy并配置它使用Tor的SOCKS:
In config.txt forward-socks4a / 127.0.0.1:9050 .
在config.txt forward-socks4a / 127.0.0.1:9050中。
then use Privoxy's default listen-address in your script:
然后在脚本中使用Privoxy的默认侦听地址:
proxy = Net::HTTP::Proxy('127.0.0.1',8118)
or use SOCKSify. According to docs:
或使用SOCKSify。根据文件:
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
No need for additional software..
无需额外的软件..
Third solution is to use SOCKSify as follows:
第三种解决方案是使用SOCKSify如下:
$ socksify_ruby localhost 9050 script.rb
which redirect all TCP connections of a Ruby script, which means you don't need to use any Proxy code at all.
它重定向Ruby脚本的所有TCP连接,这意味着您根本不需要使用任何代理代码。
For clarification you have to understand that 127.0.0.1:9050 is Tor's SOCKS address and 127.0.0.1:8118 is address of Privoxy.
为了澄清,您必须了解127.0.0.1:9050是Tor的SOCKS地址,而127.0.0.1:8118是Privoxy的地址。
#1
14
You are using HTTP proxy class, so you must provide IP of HTTP proxy. Tor Browser has not HTTP proxy bundled.
您正在使用HTTP代理类,因此您必须提供HTTP代理的IP。 Tor Browser没有绑定HTTP代理。
So you can either install some proxy software e.g. Privoxy and configure it to use Tor's SOCKS:
所以你可以安装一些代理软件,例如Privoxy并配置它使用Tor的SOCKS:
In config.txt forward-socks4a / 127.0.0.1:9050 .
在config.txt forward-socks4a / 127.0.0.1:9050中。
then use Privoxy's default listen-address in your script:
然后在脚本中使用Privoxy的默认侦听地址:
proxy = Net::HTTP::Proxy('127.0.0.1',8118)
or use SOCKSify. According to docs:
或使用SOCKSify。根据文件:
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
No need for additional software..
无需额外的软件..
Third solution is to use SOCKSify as follows:
第三种解决方案是使用SOCKSify如下:
$ socksify_ruby localhost 9050 script.rb
which redirect all TCP connections of a Ruby script, which means you don't need to use any Proxy code at all.
它重定向Ruby脚本的所有TCP连接,这意味着您根本不需要使用任何代理代码。
For clarification you have to understand that 127.0.0.1:9050 is Tor's SOCKS address and 127.0.0.1:8118 is address of Privoxy.
为了澄清,您必须了解127.0.0.1:9050是Tor的SOCKS地址,而127.0.0.1:8118是Privoxy的地址。