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.
You are using HTTP proxy class, so you must provide IP of HTTP proxy. Tor Browser has not HTTP proxy bundled.
So you can either install some proxy software e.g. Privoxy and configure it to use Tor's SOCKS:
In config.txt
forward-socks4a / 127.0.0.1:9050 .
then use Privoxy's default listen-address in your script:
proxy = Net::HTTP::Proxy('127.0.0.1',8118)
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
No need for additional software..
Third solution is to use SOCKSify as follows:
$ 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.
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.