Skip to content

Instantly share code, notes, and snippets.

@miebach
Created July 7, 2012 21:17
Show Gist options
  • Select an option

  • Save miebach/3068114 to your computer and use it in GitHub Desktop.

Select an option

Save miebach/3068114 to your computer and use it in GitHub Desktop.
Ruby function to detect if a host is up by pinging it
def host_up_ping_nt?(host)
# Checks if a host is up by pinging it.
# Version for windows. See "man ping" for other systems.
# inspired by http://stackoverflow.com/a/3561831/362951
ping_max_try = 10
cmd = "ping -n 1 #{host}"
#puts cmd
isup = false
ping_max_try.times do
result = `#{cmd}`
if ($?.exitstatus == 0)
isup = 1
break
end
end
return isup
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment