Skip to content

Instantly share code, notes, and snippets.

@awade
Created September 19, 2018 21:08
Show Gist options
  • Save awade/98ffbfd9a919e205f239f2765fb6d3e1 to your computer and use it in GitHub Desktop.
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
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