gem install proxifier
git clone https://github.com/samuelkadolph/ruby-proxifier cd ruby-proxifier && rake install
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
Proxifier::Proxy#open or by
The second purpose is to use ruby code that doesn't user proxies 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.
Executable Wrappers & Environment Variables
proxifier provides two executables:
pirb. They are simple
wrappers for your current
irb executables that requires the
"proxifier/env" script which installs hooks into
TCPSocket which will use
the proxy environment variables to proxy any
The environment variables that proxifier will check are (in order of descending precedence):
|proxy||PROXY||Requires the proxy scheme to be present.|
|Implies the SOCKS5 proxy scheme.|
|socks4a_proxy||SOCKS4A_PROXY||Implies the SOCKS4A proxy scheme.|
|socks4_proxy||PROXY||Implies the SOCKS4 proxy scheme.|
|http_proxy||HTTP_PROXY||Implies the HTTP proxy scheme.|
require "proxifier/proxy" proxy = Proxifier::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"
Environment - patching TCPSocket
require 'proxifier/env' ENV['PROXY'] = 'http://10.0.0.44:8888' # How to find the proxy ENV['PROXY_FILTER_REGEX'] = '(10\..*|localhost)' # Do not use proxy for connections inside internal net or localhost ENV['PROXY_FILTER_LIST'] = '22.214.171.124,126.96.36.199'
Afterwards, any new TCPSocket connections will use the proxy, unless they're excluded either by the specific PROXY_FILTER_LIST or the PROXY_FILTER_REGEX.
PROXY_FILTER_LIST specifies a comma separated list of hostnames or IP addresses (whichever the client code is going to use).
PROXY_FILTER_REGEX is a regular expression, where if the connection hostname (or IP address) matches the regex, connections will be made directly and not through the proxy.
Both PROXY_FILTER_LIST and PROXY_FILTER_REGEX are optional, but only one will be used.
The port defaults to 80. This is currently a limitation that may be solved in the future.
|Port defaults to 1080.|
|Not yet implemented.|
|Currently hangs. Not sure if the problem is with code or server.|