Skip to content

Instantly share code, notes, and snippets.

@DiogoAndre
Last active January 3, 2024 09:08

Revisions

  1. DiogoAndre revised this gist Jun 27, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions pinger.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    run ping.rb
  2. DiogoAndre created this gist Feb 28, 2013.
    20 changes: 20 additions & 0 deletions ping.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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"