Last active
August 29, 2015 13:59
-
-
Save huydx/10539691 to your computer and use it in GitHub Desktop.
diag.rb
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' | |
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