Skip to content

Instantly share code, notes, and snippets.

Created June 13, 2015 02:05
Show Gist options
  • Save anonymous/7f6876230f5bbf65eca3 to your computer and use it in GitHub Desktop.
Save anonymous/7f6876230f5bbf65eca3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# https://rubygems.org/gems/net-ping/versions/1.7.7
# https://github.com/chernesk/net-ping/blob/master/doc/ping.txt
require 'net/ping'
UP = true
DOWN = false
def _ping(p)
if p.ping
return true
else
return false
end
end
start_time = Time.now.to_s
_ping_comcast_gateway = Net::Ping::External.new('10.0.0.1')
_ping_secondpets = Net::Ping::HTTP.new('10.0.17.1')
if _ping(_ping_comcast_gateway)
_comcast_gateway_status = UP
print start_time + " comcast gateway up\n"
else
_comcast_gateway_status = DOWN
print start_time + " comcast gateway down\n"
end
if _ping(_ping_secondpets)
_secondpets_status = UP
print start_time + " secondpets up\n"
else
_secondpets_status = DOWN
print start_time + " secondpets down\n"
end
while true do
sleep 60
test_time = Time.now.to_s
_status = _ping(_ping_comcast_gateway)
if _status != _comcast_gateway_status
print test_time + " comcast gateway down\n"
else
print test_time + " comcast gateway up\n"
end
_comcast_gateway_status = _status
_status = _ping(_ping_secondpets)
if _status != _secondpets_status
if _secondpets_status == UP
print test_time + " secondpets down\n"
else
print test_time + " secondpets up\n"
end
_secondpets_status = _status
end
end
$ ./net_status.rb | tee net.status.log
does not work with this program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment