I tried using
Ping.pingecho("10.102.52.42", 30)
for reachability of the remote host. This statement returns null even if I'm able to ping the IP manually. Is there an efficient way to determine the reachability of the remote machine in Ruby?
Ping is a computer network administration utility used to test the reachability of a host on an Internet Protocol (IP) network and to measure the round-trip time for messages sent from the originating host to a destination computer.
I use the net-ping
gem which you need to install. Then the code is easy:
#!/usr/bin/env ruby
require 'net/ping'
def up?(host)
check = Net::Ping::External.new(host)
check.ping?
end
chost = '10.0.0.1'
puts up?(chost) # prints "true" if ping replies
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With