Module: Socksify
- Defined in:
- lib/socksify.rb,
lib/socksify/debug.rb
Defined Under Namespace
Classes: Color
Class Method Summary collapse
- .debug=(enabled) ⇒ Object
- .debug_debug(str) ⇒ Object
- .debug_error(str) ⇒ Object
- .debug_notice(str) ⇒ Object
- .proxy(server, port) ⇒ Object
- .resolve(host) ⇒ Object
Class Method Details
.debug=(enabled) ⇒ Object
28 29 30 |
# File 'lib/socksify/debug.rb', line 28 def self.debug=(enabled) @@debug = enabled end |
.debug_debug(str) ⇒ Object
32 33 34 |
# File 'lib/socksify/debug.rb', line 32 def self.debug_debug(str) debug(Color::Green, str) end |
.debug_error(str) ⇒ Object
40 41 42 |
# File 'lib/socksify/debug.rb', line 40 def self.debug_error(str) debug(Color::Red, str) end |
.debug_notice(str) ⇒ Object
36 37 38 |
# File 'lib/socksify/debug.rb', line 36 def self.debug_notice(str) debug(Color::Yellow, str) end |
.proxy(server, port) ⇒ Object
352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/socksify.rb', line 352 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) ⇒ Object
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/socksify.rb', line 322 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 |