SOCKSify Ruby
http://socksify.rubyforge.org/
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?
Modifications to class TCPSocket:
- Alias
initializeasinitialize_tcp - The new
initializecalls the old method to establish a TCP connection to the SOCKS proxy, sends the proxying destination and checks for errors
Additionally, Socksify::resolve can be used to resolve hostnames to IPv4 addresses via SOCKS. There is alsosocksify/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...>
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.Proxyfrom 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 setSOCKSProxy 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
The repository can be checked out with:
$ git-clone git://github.com/astro/socksify-ruby.git
Send patches via E-Mail.
Further ideas
Resolvreplacement 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 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.
SOCKSify Ruby的更多相关文章
- 安装cocoapods遇到两大坑-Ruby版本升级和Podfile的配置
今天安装cocoapods #移除原有ruby源 $ gem sources --remove https://rubygems.org/ #使用可用的淘宝网 $ gem sources -a htt ...
- Unable to download data from http://ruby.taobao.org/ & don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
安装cocoapods,记录两个问题! 1.镜像已经替换成了 http://ruby.taobao.org/, 还是不能不能安装cocoapods, 报错:Unable to download dat ...
- 安装了ruby后怎么安装sass
在命令行中输入 ruby -v 查看版本号 先移除默认的https://rubygems.org源,命令为gem sources --remove https://rubygems.org/,按回车 ...
- ruby 基础知识(一)
突然今天发现一大神的博客:http://www.cnblogs.com/jackluo/archive/2013/01/22/2871655.html 相信初学者会受益颇多 ruby 参考文档 ...
- ruby 基础知识(二)
ruby 中的动态方法 http://singleant.iteye.com/blog/1680382 Rails 大量使用了符号(symbol).符号看上去很像变量名,不过以冒号作为前缀.符号的例 ...
- Ruby安装Scss
Ruby安装Scss 引言 已经许久不写HTML了,今天有点以前的东西要改.但是刚装的Windows10,已经没有以前的Web开发环境了.只好重新安装. 结果Webstorm装好后配置Scss出现错误 ...
- fzf by ruby
fzf by ruby */--> fzf by ruby 1 github地址 https://github.com/junegunn/fzf 2 简介 软件通过匿名管道和grep扩展了bas ...
- The Safe Navigation Operator (&.) in Ruby
The most interesting addition to Ruby 2.3.0 is the Safe Navigation Operator(&.). A similar opera ...
- Ruby on Rails 创建https应用
1. 创建证书请求文件条件:私钥+证书签名请求+opensslyum install -y opensslmkdir /root/ssl/ && cd /root/ssl/openss ...
随机推荐
- centos6.5安装图形界面,windows远程linux图形界面
1. 查询是否已安装图形界面 yum grouplist |more 在grouplist的输出结果中的“Installed Groups:”部分中,如果你能找到“X Window System”和G ...
- JDBC编程步骤
JDBC编程步骤 加载数据库驱动. 通常使用Class类的forName()静态方法来加载驱动. Class.forName(driverClass) dirverClass: mysql---Cla ...
- DevExpress12.2.4 GridControl相关技巧
1.DevExpress12.2.4中,设置GridControl的GridView为可编辑方法如下: gvMainControl.OptionsBehavior.Editable = true; 2 ...
- Mac中安装maven3.2.1
Mac中安装maven3.2.1 原文链接:http://blog.csdn.net/f_zongjian/article/details/24144803 本机OS X:10.9,未安装XCode, ...
- 使用Rails 4.2+ 测试异步邮件系统
[导读]异步测试总是一个很大的问题,邮件发送测试更是让很多开发同学不知道从哪里入手.在新版的Rails里,这类测试在很大程度上被简化了. 以下为译文 在编写需要发送邮件的应用时,控制器是绝不能被阻塞的 ...
- HDU 2674 N!Again(数学思维水题)
题目 //行开始看被吓一跳,那么大,没有头绪, //看了解题报告,发现这是一道大大大的水题,,,,,//2009 = 7 * 7 * 41//对2009分解,看它有哪些质因子,它最大的质因子是41,那 ...
- LA 4727
Integers 1, 2, 3,..., n are placed on a circle in the increasing order as in the following figure. W ...
- [网页设计]Ajax、Comet与Websocket--转
从http协议说起 1996年IETF HTTP工作组发布了HTTP协议的1.0版本 ,到现在普遍使用的版本1.1,HTTP协议经历了17 年的发展.这种分布式.无状态.基于TCP的请求/响应式.在 ...
- javaScript解决Form的嵌套
HTML是不允许FORM嵌套的,用一个简单的JAVASCRIPT就可以解决问题了 <script language=javascript> function process(v){ if( ...
- [iOS]URL编码和解码
1. 首先来看下什么样的是URL编码(字符串中带有%22 类似这样的) NSString *str = @"http://m.tuniu.com/api/home/data/index/c/ ...