GithubHelp home page GithubHelp logo

isabella232 / socksify-ruby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shopify/socksify-ruby

0.0 0.0 0.0 93 KB

Redirect any TCP connection initiated by a Ruby script through a SOCKS5 proxy

Home Page: http://socksify.rubyforge.org/

License: Other

Ruby 100.00%

socksify-ruby's Introduction

Socksify

What is it?

Socksify 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 - prepends a new initialize method which:

  • Calls super to establish a TCP connection to the SOCKS proxy
  • Sends the proxying destination
  • Checks for errors

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.

Installation

$ gem install socksify

Usage

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 = "127.0.0.1"
TCPSocket::socks_port = 9050
rubyforge_www = TCPSocket.new("rubyforge.org", 80)
# => #<TCPSocket:0x...>

Using block only:

require 'socksify'
require 'open-uri'

Socksify::proxy("127.0.0.1", 9050) {
  open('http://rubyforge.org').read
  # => #<String: rubyforge's html>
}

Please note: socksify is not thread-safe when used this way! socks_server and socks_port are stored in class @@-variables, and applied to all threads and fibers of application.

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('http://rubyforge.org/')
Net::HTTP.SOCKSProxy('127.0.0.1', 9050).start(uri.host, uri.port) do |http|
  http.get(uri.path)
end
# => #<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

Socksify::resolve("spaceboyz.net")
# => "87.106.131.203"

Debugging

Colorful diagnostic messages can be enabled via:

Socksify::debug = true

Development

This repository can be checked out with:

$ git clone [email protected]:astro/socksify-ruby.git

Send patches via GitHub.

Further ideas

  • Resolv replacement code, so that programs which resolve by themselves don't leak DNS queries
  • IPv6 address support
  • UDP as soon as Tor supports it
  • Perhaps using standard exceptions for better compatibility when acting as a drop-in?

Author

License

Socksify 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.

socksify-ruby's People

Contributors

astro avatar awakia avatar bachue avatar christopherthorpe avatar ddollar avatar florinasavoaie avatar hotchpotch avatar michaelxavier avatar midori-armstrong-shopify avatar musybite avatar sticnarf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.