百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

socksify-ruby

> 编程语言
开源

将由 Ruby 脚本启动的任何 TCP 连接重定向到 SOCKS5 代理

171 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

将由 Ruby 脚本启动的任何 TCP 连接重定向到 SOCKS5 代理

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?

rb
require 'socksify/http'

This adds a new class method Net::HTTP.socks_proxy which takes the host and port address of a socks proxy. Once set, all requests will be routed via socks. This is acheived by patching a private method in Net::HTTP, as sadly Ruby no longer has native socks proxy support out of the box.

Additionally, Socksify.resolve can be used to resolve hostnames to IPv4 addresses 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 (Deprecated in Ruby 3.1 onwards)

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

rb
require 'socksify'

TCPSocket.socks_server = "127.0.0.1"
TCPSocket.socks_port = 9050
rubyforge_www = TCPSocket.new("rubyforge.org", 80)
# => #

Use Net::HTTP explicitly via SOCKS

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

rb
require 'socksify/http'

uri = URI.parse('http://ipecho.net/plain')
Net::HTTP.socks_proxy('127.0.0.1', 9050).start(uri.host, uri.port) do |http|
  req = Net::HTTP::Get.new uri
  resp = http.request(req)
  puts resp.inspect
  puts resp.body
end
# => #
# => 

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

Authentication

rb
require 'socksify/http'

uri = URI.parse('http://ipecho.net/plain')
Net::HTTP.socks_proxy('127.0.0.1', 1080, username: 'my_username', password: 'my_pwd').start(uri.host, uri.port) do |http|
  req = Net::HTTP::Get.new uri
  resp = http.request(req)
  puts resp.inspect
  puts resp.body
end

Resolve addresses via SOCKS

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

Testing and Debugging

A tor proxy and socks5 proxy with auth is required before running the tests.

  • Install tor from your usual package manager, check it is running with pidof tor
  • Start a SOCKS5 proxy using Docker docker run -d --name socks5 -p 1080:1080 -e PROXY_USER=user -e PROXY_PASSWORD=password serjs/go-socks5-proxy

Then run the tests with: bundle exec rake

Colorful diagnostic messages are enabled by default via:

rb
Socksify::debug = true`

Development

The repository can be checked out with:

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

Send patches via pull requests.

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

  • Stephan Maka

License

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.

Issues· 7 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyrubyrubygemsockssocks5

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言