|
|
||
|---|---|---|
| bin | ||
| lib | ||
| .gitignore | ||
| Gemfile | ||
| LICENSE | ||
| README.md | ||
| Rakefile | ||
| sockets.gemspec | ||
README.md
ruby-sockets
Installing
Recommended
gem install sockets
Edge
git clone https://github.com/samuelkadolph/ruby-sockets
cd ruby-sockets && rake install
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
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. |