Skip to content

Instantly share code, notes, and snippets.

@huydx
Last active August 29, 2015 13:59
Show Gist options
  • Save huydx/10539691 to your computer and use it in GitHub Desktop.
Save huydx/10539691 to your computer and use it in GitHub Desktop.
diag.rb
require 'net/ping'
require 'colorize'
require 'terminal-notifier'
class InternetDiagnosis
def initialize
@host = 'www.google.com'
@concurrency = 3
@prev_error = nil
end
def process
icmp = Net::Ping::ICMP.new(@host, nil, 0.1) #default 0.1 second for good condition
if icmp.ping
print " good \r".yellow
else
print " not good\r".red
current = Time.now
if @prev_error
echo if current - @prev_error > 2 #report each 2 seconds
else
echo
end
@prev_error = current
end
end
def echo
system("echo 'mat mang me roi!' | terminal-notifier -sound default")
end
def run
loop do
sleep 1
process
$stdout.flush
end
end
end
InternetDiagnosis.new.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment