Skip to content

Instantly share code, notes, and snippets.

@uluQulu
Last active August 23, 2018 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uluQulu/1df1f972576b26cc1b6741e9283449c2 to your computer and use it in GitHub Desktop.
Save uluQulu/1df1f972576b26cc1b6741e9283449c2 to your computer and use it in GitHub Desktop.
A universal server ping tool
def ping_server(host):
"""
Returns True if host (str) responds to a ping request.
Remember that a host may not respond to a ping (ICMP) request even if the host name is valid.
"""
# Ping command count option as function of OS
param = "-n" if system().lower()=="windows" else "-c"
# Building the command. Ex: "ping -c 1 google.com"
command = ' '.join(["ping", param, '1', str(host)])
need_sh = False if system().lower()=="windows" else True
# Pinging
return call(command, shell=need_sh) == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment