Created
September 19, 2018 21:08
-
-
Save awade/98ffbfd9a919e205f239f2765fb6d3e1 to your computer and use it in GitHub Desktop.
Simple python function to check if host is up using ping, allows setting of waittime
This file contains 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 HostUp(hostname, waittime=1000): | |
'''Function returns True if host IP returns a ping, else False''' | |
assert isinstance(hostname, str), \ | |
"IP/hostname must be provided as a string." | |
if os.system("ping -c 1 -W " + str(waittime) + " " + | |
hostname + " > /dev/null 2>&1") is 0: | |
HOST_UP = True | |
else: | |
HOST_UP = False | |
return HOST_UP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment