astro / socksify-ruby

Redirect any TCP connection initiated by a Ruby script through a SOCKS5 proxy
http://socksify.rubyforge.org/
Other
165 stars 79 forks source link

in `pack': can't convert String into Integer (TypeError) #8

Closed DimShadoWWW closed 9 years ago

DimShadoWWW commented 13 years ago

I'm trying to use socksify-ruby for an script I made to download mangas from submanga.com using Mechanize , but when I tried to execute this:

socksify_ruby 127.0.0.1 1080 download.rb http://submanga.com/Code_Breaker/completa 41..50

It aborts with this error:

./download.rb:120: warning: toplevel constant Mechanize referenced by Mechanize::Mechanize
/home/XXX/.gem/ruby/1.8/gems/socksify-1.4.0/lib/socksify.rb:214:in 'pack': can't convert String into Integer (TypeError)
    from /home/XXX/.gem/ruby/1.8/gems/socksify-1.4.0/lib/socksify.rb:214:in 'socks_connect'
    from /home/XXX/.gem/ruby/1.8/gems/socksify-1.4.0/lib/socksify.rb:156:in 'initialize'
    from /usr/lib/ruby/1.8/net/http.rb:560:in 'open'
    from /usr/lib/ruby/1.8/net/http.rb:560:in 'connect'
    from /usr/lib/ruby/1.8/timeout.rb:62:in 'timeout'
    from /usr/lib/ruby/1.8/timeout.rb:93:in 'timeout'
    from /usr/lib/ruby/1.8/net/http.rb:560:in 'connect'
    from /usr/lib/ruby/1.8/net/http.rb:553:in 'do_start'
    from /usr/lib/ruby/1.8/net/http.rb:548:in 'start'
    from /home/XXX/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:527:in 'fetch_page'
    from /home/XXX/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:259:in 'get'
    from ./download.rb:130
    from /home/XXX/.gem/ruby/1.8/gems/socksify-1.4.0/bin/socksify_ruby:13:in 'load'
    from /home/XXX/.gem/ruby/1.8/gems/socksify-1.4.0/bin/socksify_ruby:13
    from /home/XXX/lib/ruby/gems/1.8/bin/socksify_ruby:19:in 'load'
    from /home/XXX/lib/ruby/gems/1.8/bin/socksify_ruby:19

I enabled the @debug variable, and added this line before the line 214:

Socksify::debug_debug "#{[port][0].class}   #{[port][0]}"

and this returned:

./download.rb:120: warning: toplevel constant Mechanize referenced by Mechanize::Mechanize
02:45:23 Connecting to SOCKS server 127.0.0.1:1080
02:45:23 Sending no authentication
02:45:23 Waiting for authentication reply
02:45:23 Sending destination address
02:45:23 05
02:45:23 localhost
02:45:23 String   8118
/home/XXX/.gem/ruby/1.8/gems/socksify-1.4.0/lib/socksify.rb:215:in 'pack': can't convert String into Integer (TypeError)
    from /home/XXX/.gem/ruby/1.8/gems/socksify-1.4.0/lib/socksify.rb:215:in 'socks_connect'
    from /home/XXX/.gem/ruby/1.8/gems/socksify-1.4.0/lib/socksify.rb:156:in 'initialize'
    from /usr/lib/ruby/1.8/net/http.rb:560:in 'open'
    from /usr/lib/ruby/1.8/net/http.rb:560:in 'connect'
    from /usr/lib/ruby/1.8/timeout.rb:62:in 'timeout'
    from /usr/lib/ruby/1.8/timeout.rb:93:in 'timeout'
    from /usr/lib/ruby/1.8/net/http.rb:560:in 'connect'
    from /usr/lib/ruby/1.8/net/http.rb:553:in 'do_start'
    from /usr/lib/ruby/1.8/net/http.rb:548:in 'start'
    from /home/XXX/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:527:in 'fetch_page'
    from /home/XXX/.gem/ruby/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:259:in 'get'
    from ./download.rb:130
    from /home/XXX/.gem/ruby/1.8/gems/socksify-1.4.0/bin/socksify_ruby:13:in 'load'
    from /home/XXX/.gem/ruby/1.8/gems/socksify-1.4.0/bin/socksify_ruby:13
    from /home/XXX/lib/ruby/gems/1.8/bin/socksify_ruby:19:in 'load'
    from /home/XXX/lib/ruby/gems/1.8/bin/socksify_ruby:19

anything to test??

astro commented 13 years ago

What a noble use case :-)

Do I understand you correctly that Mechanize passes the port as a String?

Unfortunately, SOCKS5 expects nothing else than a 16 bit number. Should we look into /etc/services? Can Ruby do that for us already?

musybite commented 10 years ago

Ruby (libc, in fact) already can do this:

1.9.3-p448 :003 > Socket.getservbyname 'http'
 => 80 
1.9.3-p448 :004 > Socket.getservbyname '8118'
 => 8118