Created
July 7, 2012 21:17
-
-
Save miebach/3068114 to your computer and use it in GitHub Desktop.
Ruby function to detect if a host is up by pinging it
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
| 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