Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this gem only works on Linux? #18

Open
victorhazbun opened this issue Feb 20, 2018 · 15 comments
Open

this gem only works on Linux? #18

victorhazbun opened this issue Feb 20, 2018 · 15 comments

Comments

@victorhazbun
Copy link

I installed it and started building a "Network ping sweeping", but as soon as I run my program I got this issue:

$ ruby network_ping_sweeping.rb 66.220.144.0
Traceback (most recent call last):
  3: from network_ping_sweeping.rb:6:in `<main>'
  2: from network_ping_sweeping.rb:6:in `new'
  1: from /Users/victor/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/net-ping-2.0.2/lib/net/ping/icmp.rb:31:in `initialize'
/Users/victor/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/net-ping-2.0.2/lib/net/ping/icmp.rb:43:in 
`rescue in initialize': undefined method `StandardError' for #<Net::Ping::ICMP:0x00007f90b589e688> (NoMethodError)

It seems like I need to install the cap2 gem which only runs on Linux.

@radiospiel
Copy link

maybe, but also the source code contains a serious syntax error, here:

raise StandardError 'requires root privileges or setcap net_raw'

This must be

raise StandardError, 'requires root privileges or setcap net_raw'

instead.

@chernesk
Copy link
Collaborator

Got it. A new release will be made in a few hours.

@chernesk
Copy link
Collaborator

@victorhazbun Is there some other gem that you would suggest, or is there a pull request that you can make which resolves the issue?

@chernesk
Copy link
Collaborator

Exception fix pushed.

Will look into cap2 issue as time allows. Does anyone else have issues or can provide the environment that they're using?

@djberg96
Copy link

djberg96 commented Aug 4, 2018

@victorhazbun what makes you think you need the cap2 gem? Otherwise, I think it's just a syntax error, and @chernesk can close this.

@ForeverZer0
Copy link

ForeverZer0 commented May 31, 2019

@djberg96 The cap2 gem is indeed an undocumented dependency (at least on Linux when using the Net::Ping::ICMP class. Not even sure what possible indication you have to think it is a syntax problem.

Just installed this (Arch Linux), and also get this error, although easily remedied by installing the cap2 gem. Unfortunately, the cap2 gem requires sudo to even be required, which is somewhat problematic for my needs.

This gem could benefit a lot from some clearer documentation, especially in regards to platform and protocol specifics, such as dependencies, etc. Was hoping for a cleaner approach than using system to invoke ping and timeout (need higher granularity than the 1 second minimum timeout ping offers), and then extracting info with regular expressions. It works, but is ugly...

@djberg96
Copy link

Not even sure what possible indication you have to think it is a syntax problem.

There was a missing comma after a raise call as @radiospiel mentioned above.

@djberg96
Copy link

@ForeverZer0 You are right that cap2 is an undocumented dependency, not sure when it was added, but the gemspec should be updated.

But, one way or another, icmp pings require root privs (on unixy systems anyway) since you're making a raw socket. Your command line ping command runs suid root, btw.

As for your needs, are none of the other ping types viable?

@chernesk
Copy link
Collaborator

chernesk commented May 31, 2019 via email

@djberg96
Copy link

@chernesk looks like you already fixed the missing comma a while back.

@chernesk
Copy link
Collaborator

I was responding from email, so I hadn't taken a look.

Anything else we want to change while I'm in there?

@djberg96
Copy link

@chernesk Not sure, but I do see some http-ping test failures when I run the tests locally on my RHEL7 laptop.

>rake
/home/dberger/.rbenv/versions/2.5.4/bin/ruby -w -I"lib:test" -I"/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib" "/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/rake_test_loader.rb" "test/test_net_ping.rb" 
/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/utility.rb:35: warning: assigned but unused variable - uri
Loaded suite /home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/rake_test_loader
Started
......................./home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:166:in `block in <class:TC_Net_Ping_HTTP>'
     163:   end
     164: 
     165:   test 'code attribute is set' do
  => 166:     assert_true(@http.ping)
     167:     assert_equal('200', @http.code)
     168:   end
     169: 
Failure: test: code attribute is set(TC_Net_Ping_HTTP):
  <true> expected but was
  <false>
=======================================================================================================================
/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
../home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:96:in `block in <class:TC_Net_Ping_HTTP>'
     93:   end
     94: 
     95:   test 'duration returns a float value on a successful ping' do
  => 96:     assert_true(@http.ping)
     97:     assert_kind_of(Float, @http.duration)
     98:   end
     99: 
Failure: test: duration returns a float value on a successful ping(TC_Net_Ping_HTTP):
  <true> expected but was
  <false>
=======================================================================================================================
./home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:151:in `block in <class:TC_Net_Ping_HTTP>'
     148:   end
     149: 
     150:   test 'exception attribute is nil if the ping is successful' do
  => 151:     assert_true(@http.ping)
     152:     assert_nil(@http.exception)
     153:   end
     154: 
Failure: test: exception attribute is nil if the ping is successful(TC_Net_Ping_HTTP):
  <true> expected but was
  <false>
=======================================================================================================================
../home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:221:in `block in <class:TC_Net_Ping_HTTP>'
     218:   test 'http 502 sets code' do
     219:     @http = Net::Ping::HTTP.new("http://http502.com")
     220:     assert_false(@http.ping)
  => 221:     assert_equal('502', @http.code)
     222:   end
     223: 
     224:   test 'ping against https site defaults to port 443' do
<"502"> expected but was
<nil>
Failure: test: http 502 sets code(TC_Net_Ping_HTTP)
=======================================================================================================================
/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:215:in `block in <class:TC_Net_Ping_HTTP>'
     212:   test 'http 502 sets exception' do
     213:     @http = Net::Ping::HTTP.new("http://http502.com")
     214:     assert_false(@http.ping)
  => 215:     assert_equal('Bad Gateway', @http.exception)
     216:   end
     217: 
     218:   test 'http 502 sets code' do
<"Bad Gateway">(UTF-8) expected but was
<"undefined method `close' for #<FakeWeb::StubSocket:0x0000557014b2bab8>\n" +
"Did you mean?  closed?\n" +
"               clone">(US-ASCII)

diff:
+ undefined method `close' for #<FakeWeb::StubSocket:0x0000557014b2bab8>
? B         a         d Gateway
? Did you me n?  close ?       
+                clone
  
? Encoding: UTF-8    
?            S  ASCII
Failure: test: http 502 sets exception(TC_Net_Ping_HTTP)
=======================================================================================================================
./home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:231:in `block in <class:TC_Net_Ping_HTTP>'
     228: 
     229:   test 'ping against https site works as expected' do
     230:     @http = Net::Ping::HTTP.new(@uri_https)
  => 231:     assert_true(@http.ping)
     232:   end
     233: 
     234:   test 'ping with get option' do
Failure: test: ping against https site works as expected(TC_Net_Ping_HTTP):
  <true> expected but was
  <false>
=======================================================================================================================
/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
../home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
../home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:83:in `block in <class:TC_Net_Ping_HTTP>'
     80:   end
     81: 
     82:   test 'ping should succeed for a valid website' do
  => 83:     assert_true(@http.ping?)
     84:   end
     85: 
     86:   test 'ping should fail for an invalid website' do
Failure: test: ping should succeed for a valid website(TC_Net_Ping_HTTP):
  <true> expected but was
  <false>
=======================================================================================================================
/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
./home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
./home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
./home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:237:in `block in <class:TC_Net_Ping_HTTP>'
     234:   test 'ping with get option' do
     235:     @http = Net::Ping::HTTP.new(@uri)
     236:     @http.get_request = true
  => 237:     assert_true(@http.ping)
     238:   end
     239: 
     240:   test 'ping with http proxy' do
Failure: test: ping with get option(TC_Net_Ping_HTTP):
  <true> expected but was
  <false>
=======================================================================================================================
/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:244:in `block in <class:TC_Net_Ping_HTTP>'
     241:     ENV['http_proxy'] = "http://proxymoxie:3128"
     242:     @http = Net::Ping::HTTP.new(@uri)
     243:     @http.get_request = true
  => 244:     assert_true(@http.ping)
     245:     assert_true(@http.proxied)
     246:   end
     247: 
Failure: test: ping with http proxy(TC_Net_Ping_HTTP):
  <true> expected but was
  <false>
=======================================================================================================================
/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:252:in `block in <class:TC_Net_Ping_HTTP>'
     249:     ENV['https_proxy'] = "http://proxymoxie:3128"
     250:     @http = Net::Ping::HTTP.new(@uri_https)
     251:     @http.get_request = true
  => 252:     assert_true(@http.ping)
     253:     assert_true(@http.proxied)
     254:   end
     255: 
Failure: test: ping with https proxy(TC_Net_Ping_HTTP):
  <true> expected but was
  <false>
=======================================================================================================================
/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:260:in `block in <class:TC_Net_Ping_HTTP>'
     257:     ENV['no_proxy'] = "google.com"
     258:     @http = Net::Ping::HTTP.new(@uri)
     259:     @http.get_request = true
  => 260:     assert_true(@http.ping)
     261:     assert_false(@http.proxied)
     262:   end
     263: 
Failure: test: ping with no_proxy(TC_Net_Ping_HTTP):
  <true> expected but was
  <false>
=======================================================================================================================
/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:209:in `block in <class:TC_Net_Ping_HTTP>'
     206:     @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
     207:     @http.redirect_limit  = 0
     208:     assert_false(@http.ping)
  => 209:     assert_equal("Redirect limit exceeded", @http.exception)
     210:   end
     211: 
     212:   test 'http 502 sets exception' do
<"Redirect limit exceeded">(UTF-8) expected but was
<"undefined method `close' for #<FakeWeb::StubSocket:0x0000557014a40cc0>\n" +
"Did you mean?  closed?\n" +
"               clone">(US-ASCII)

diff:
? R      edi                 r      e           c  t limit ex             ceeded
? undefin   method `close' fo  #<Fak Web::StubSo ke :0       0000557014a40 c0>  
+ Did you mean?  closed?
+                clone
  
? Encoding: UTF-8    
?            S  ASCII
Failure: test: ping with redirect limit set to zero fails(TC_Net_Ping_HTTP)
=======================================================================================================================
/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:181:in `block in <class:TC_Net_Ping_HTTP>'
     178: 
     179:   test 'ping with user agent' do
     180:     @http.user_agent = "KDDI-CA32"
  => 181:     assert_true(@http.ping)
     182:     assert_equal("KDDI-CA32", FakeWeb.last_request["user-agent"])
     183:   end
     184: 
Failure: test: ping with user agent(TC_Net_Ping_HTTP):
  <true> expected but was
  <false>
=======================================================================================================================
..../home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
.../home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/fakeweb-1.3.0/lib/fake_web/responder.rb:58: warning: File.exists? is a deprecated name, use File.exist? instead
F
=======================================================================================================================
/home/dberger/Dev/net-ping/test/test_net_ping_http.rb:196:in `block in <class:TC_Net_Ping_HTTP>'
     193: 
     194:   test 'redirects succeed by default' do
     195:     @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
  => 196:     assert_true(@http.ping)
     197:   end
     198: 
     199:   test 'redirect fail if follow_redirect is set to false' do
Failure: test: redirects succeed by default(TC_Net_Ping_HTTP):
  <true> expected but was
  <false>
=======================================================================================================================
.......................................
Finished in 10.536726948 seconds.
-----------------------------------------------------------------------------------------------------------------------
96 tests, 178 assertions, 14 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
85.4167% passed
-----------------------------------------------------------------------------------------------------------------------
9.11 tests/s, 16.89 assertions/s
rake aborted!
Command failed with status (1): [ruby -w -I"lib:test" -I"/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib" "/home/dberger/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/rake_test_loader.rb" "test/test_net_ping.rb" ]

Tasks: TOP => default => test
(See full trace by running task with --trace)

I'm not sure how active fakeweb is. It was considered a dead project for a time, though I can see that there were some updates a couple years ago.

@djberg96
Copy link

@chernesk Setting up some sort of CI would probably be a good idea - perhaps Travis (Linux) and Appveyor (Windows).

@chernesk
Copy link
Collaborator

chernesk commented May 31, 2019 via email

@ForeverZer0
Copy link

ForeverZer0 commented May 31, 2019

@djberg96 Totally missed the syntax issue, you have better eyes than me xD

I realize ping is runs as root, my first solution was to write a C extension simply that created raw sockets, etc, etc, but quickly realized the issue with root privileges, not to mention it was a larger endeavor than I intended for the scope of my simple app, as well as trying to reinvent the wheel to a degree, so I went looking for gems, and this seems the best option.

I CAN use the other classes without root, and TBH, for 95% or more of situations, the app will require root anyways (just a custom mirrorlist generator for pacman on Arch), so this is not a critical issue, just not ideal, as it has a few options where requiring root just doesn't make sense. It was more a matter of consistency and personal choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants