Ruby, Tor and Net::HTTP::Proxy
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.
Connect to Tor network with ruby
I think it's like specifying proxy server for your HTTP connection. I don't know how it works in Ruby. But it will not be different from configuring browsers. Just set proxy server setting to 127.0.0.1:8118
.
How to Build and Send an HTTP Request to a Tor Hidden Service with Ruby
Curl only uses a proxy if you set it up in your "curl"-block.
For example:
c = Curl::Easy.new() do |curl|
curl.proxy_tunnel = true
curl.proxy_type = Curl::CURLPROXY_SOCKS5 # also available and default Curl::CURLPROXY_HTTP
curl.proxy_url = '127.0.0.1:9050' # local tor client/proxy
curl.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0" #the user agent string from the most recent version of the tor browser
curl.verbose = true
curl.url = url # your example url
curl.perform
curl.inspect
end
Unfortunately curl does not use the proxy for hostname resolution. In other words, I did't find a way to force curl to use the proxy for hostname resolution.
But you can try
#enable socksify debug
Socksify::debug = true
#own try via direct use of socksify and Net::HTTP
uri = URI.parse('http://am4wuhz3zifexz5u.onion/') #a known, functioning hidden service
# some debug stuff - just ignore ;-)
puts uri
puts uri.host
puts uri.port
puts uri.path
res1 = Net::HTTP.SOCKSProxy('127.0.0.1', 9050).start(uri.host, uri.port) do |http|
http.get(uri.path)
end
Ruby - Socks4 proxy with WWW::Mechanize and NET::HTTP::GET
You probably want to look at Ruby socksify. I don't think that the HTTP client has any support for SOCKS proxies; only HTTP proxies for HTTP.
Connect to a password protected FTP through PROXY in Ruby
I realise that you asked this question over 6 months ago, but I recently had a similar issue and found that this (unanswered) question is the top Google result, so I thought I would share my findings.
mudasobwa's comment below your original post has a link to the net/ftp documentation which explains how to use a SOCKS proxy...
Although you don't mention a specific requirement for a HTTP proxy in your original post, it seems obvious to me that is what you were trying to use. As I'm sure you're aware, this makes the SOCKS documentation totally irrelevant.
The following code has been tested on ruby-1.8.7-p357
using an HTTP proxy that does not require authentication:
file = File.open('myfile.gz', 'w')
http = Net::HTTP.start('myproxy.com', '9293')
resp, data = http.get('ftp://login:password@ftp.website.com')
file.write(data) if resp.code == "200"
file.close unless file.nil?
Source
This should give you a good starting point to figure the rest out for yourself.
To get you going, I would guess that you could use user:pass@myproxy.com
for basic auth, or perhaps sending a Proxy-Authorization
header in your GET request.
How can modify HTTParty gem for using Net::HTTP.SOCKSProxy
You could use another gem such as excon
this gem support http proxy
Related Topics
Why Is "❨╯°□°❩╯︵┻━┻" with Such an Encoding Used for a Method Name
Change HTML Form Id Generated by Form_For Rails 3.1
Ruby, Using Regex to Find Something in Between Two Strings
Is the Unix Philosophy Falling Out of Favor in the Ruby Community
Passenger: Cannot Load Such File Rubygems/Builder
How to Set a Cookie with a (Ruby) Rack Middleware Component
Running Parallel Selenium Tests with Capybara
Responding with Multiple JSON Renders. (Ruby/Rails)
Provide Value for Self When Using Proc#Call
Ruby: How to Calculate a Path Relative to Another One
Document Model Attributes with Yard
Have Devise Create a Subdomain on Registration
Simple Neural Network Can't Learn Xor