I can ping google from my local machine, but can anyone tell me why I might be getting “false” when I run the following in IRB on the same machine? Really frustrating as a ping is supposed to be the most simple network op and I just can’t get it to work!
1.9.2-p290 :001 > require "net/ping"
=> true
1.9.2-p290 :003 > pinger = Net::Ping::External.new("http://www.google.com")
=> #<Net::Ping::External:0x88eac30 @host="http://www.google.com", @port=7, @timeout=5, @exception=nil, @warning=nil, @duration=nil>
1.9.2-p290 :004 > pinger.ping
=> false
1.9.2-p290 :005 >
The following is not a valid host/domain name (although it is a valid URL):
Thus, the DNS resolution will fail and, having no target IP, no ping can be sent.
I’m sure you didn’t use that exact host for the command-line
ping🙂 As Gareth notes, doing so would look similar to:A “normal ping”, which is being attempted here, and an “HTTP ping” are different. Contrast this usage with
Net::Ping::HTTP, which does take a URL, for instance.Happy coding.
(Either “google.com” or “www.google.com” would be suitable host names.)