# ruby-sockets ## Installing ### Recommended ``` gem install sockets ``` ### Edge ``` git clone https://github.com/samuelkadolph/ruby-sockets cd ruby-sockets && rake install ``` ## Rationale This gem was created for 2 purposes. First is to enable ruby programmers to use HTTP or SOCKS proxies interchangeably when using TCPSockets. Either manually with `Sockets::Proxy#open` or by `require "sockets/env"`. The second purpose is to use ruby code that doesn't consider a proxy for users that have to use proxies.
The pruby and pirb executables are simple wrappers for their respective ruby executables that support proxies from environment variables. ## Usage ### Environment Variables & Executable Wrappers sockets provides two executables: `pruby` and `pirb`. They are simple wrappers for your current `ruby` and `irb` executables that `require "sockets/env"` which installs hooks to `TCPSocket` which will use your proxy environment variables whenever a `TCPSocket` is created. sockets will use the `proxy`, `PROXY`, `socks_proxy` and `http_proxy` environment variables (in that order) to determine what proxy to use. ### Ruby ```ruby require "sockets/proxy" proxy = Sockets::Proxy("socks://localhost") socket = proxy.open("www.google.com", 80) socket << "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n" socket.gets # => "HTTP/1.1 200 OK\r\n" ``` ## Supported Proxies
Protocol Formats Notes
HTTP
http://[username[:password]@]host[:port][?tunnel=false]
The port defaults to 80. This is currently a limitation that may be solved in the future.
Appending ?tunnel=false forces the proxy to not use CONNECT.
SOCKS5
socks://[username[:password]@]host[:port]
socks5://[username[:password]@]host[:port]
Port defaults to 1080.
SOCKS4
socks4://[username@]ip1.ip2.ip3.ip4[:port]
Currently hangs. Not sure if the problem is with code or server.
SOCKS4A
socks4a://[username@]host[:port]
Not yet implemented.