Last active
August 23, 2018 17:13
-
-
Save uluQulu/1df1f972576b26cc1b6741e9283449c2 to your computer and use it in GitHub Desktop.
A universal server ping tool
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 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