-
-
Save sergii/c7d8f8e5e50d51bb0058ac80227535b4 to your computer and use it in GitHub Desktop.
Simple ICMP Ping script in Ruby. Using the Net-Ping gem https://github.com/djberg96/net-ping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/ping' | |
@icmp = Net::Ping::ICMP.new('142.40.81.34') | |
rtary = [] | |
pingfails = 0 | |
repeat = 5 | |
puts 'starting to ping' | |
(1..repeat).each do | |
if @icmp.ping | |
rtary << @icmp.duration | |
puts "host replied in #{@icmp.duration}" | |
else | |
pingfails += 1 | |
puts "timeout" | |
end | |
end | |
avg = rtary.inject(0) {|sum, i| sum + i}/(repeat - pingfails) | |
puts "Average round-trip is #{avg}\n" | |
puts "#{pingfails} packets were droped" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run ping.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment