SOCKSify Ruby

What is it?

SOCKSify Ruby redirects any TCP connection initiated by a Ruby script through a SOCKS5 proxy. It serves as a small drop-in alternative to tsocks, except that it handles Ruby programs only and doesn't leak DNS queries.

How does it work?

Modifications to class TCPSocket:

Additionally, Socksify::resolve can be used to resolve hostnames to IPv4 addresses via SOCKS. There is also socksify/http enabling Net::HTTP to work via SOCKS.


$ gem install socksify


Redirect all TCP connections of a Ruby program

Run a Ruby script with redirected TCP through a local Tor anonymizer:

$ socksify_ruby localhost 9050 script.rb

Explicit SOCKS usage in a Ruby program

Set up SOCKS connections for a local Tor anonymizer, TCPSockets can be used as usual:

require 'socksify'
TCPSocket::socks_server = ""
TCPSocket::socks_port = 9050
rubyforge_www ="", 80)
# => #<TCPSocket:0x...>

Use Net::HTTP explicitly via SOCKS

Require the additional library socksify/http and use the Net::HTTP.SOCKSProxy method. It is similar to Net:HTTP.Proxy from the Ruby standard library:

require 'socksify/http'
uri = URI.parse('')
Net::HTTP.SOCKSProxy('', 9050).start(, uri.port) do |http|
# => #<Net::HTTPOK 200 OK readbody=true>

Note that Net::HTTP.SOCKSProxy never relies on TCPSocket::socks_server/socks_port. You should either set SOCKSProxy arguments explicitly or use Net::HTTP directly.

Resolve addresses via SOCKS

# => ""


Colorful diagnostic messages can be enabled via:

Socksify::debug = true


The repository can be checked out with:

$ git-clone git://

Send patches via E-Mail.

Further ideas



SOCKSify Ruby is distributed under the terms of the GNU General Public License version 3 (see file COPYING) or the Ruby License (see file LICENSE) at your option.