module Socksify
Public Class Methods
debug=(enabled)
click to toggle source
# File lib/socksify/debug.rb, line 28 def self.debug=(enabled) @@debug = enabled end
debug_debug(str)
click to toggle source
# File lib/socksify/debug.rb, line 32 def self.debug_debug(str) debug(Color::Green, str) end
debug_error(str)
click to toggle source
# File lib/socksify/debug.rb, line 40 def self.debug_error(str) debug(Color::Red, str) end
debug_notice(str)
click to toggle source
# File lib/socksify/debug.rb, line 36 def self.debug_notice(str) debug(Color::Yellow, str) end
proxy(server, port) { || ... }
click to toggle source
# File lib/socksify.rb, line 357 def self.proxy(server, port) default_server = TCPSocket::socks_server default_port = TCPSocket::socks_port begin TCPSocket::socks_server = server TCPSocket::socks_port = port yield ensure TCPSocket::socks_server = default_server TCPSocket::socks_port = default_port end end
resolve(host)
click to toggle source
# File lib/socksify.rb, line 327 def self.resolve(host) s = TCPSocket.new begin req = String.new Socksify::debug_debug "Sending hostname to resolve: #{host}" req << "\005" if host =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ # to IPv4 address req << "\xF1\000\001" + [$1.to_i, $2.to_i, $3.to_i, $4.to_i ].pack('CCCC') elsif host =~ /^[:0-9a-f]+$/ # to IPv6 address raise "TCP/IPv6 over SOCKS is not yet supported (inet_pton missing in Ruby & not supported by Tor" req << "\004" else # to hostname req << "\xF0\000\003" + [host.size].pack('C') + host end req << [0].pack('n') # Port s.write req addr, _port = s.socks_receive_reply Socksify::debug_notice "Resolved #{host} as #{addr} over SOCKS" addr ensure s.close end end
Private Class Methods
debug(color, str)
click to toggle source
# File lib/socksify/debug.rb, line 46 def self.debug(color, str) if defined?(@@debug) && @@debug puts "#{color}#{now_s}#{Color::Reset} #{str}" end end
now_s()
click to toggle source
# File lib/socksify/debug.rb, line 52 def self.now_s Time.now.strftime('%H:%M:%S') end