Skip to content

Instantly share code, notes, and snippets.

@aweher
Created March 19, 2018 12:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aweher/fdaa91abc958aaae54086a9ae5b30a1d to your computer and use it in GitHub Desktop.
Save aweher/fdaa91abc958aaae54086a9ae5b30a1d to your computer and use it in GitHub Desktop.
Ping in python 3 without output or using subprocess
def is_alive(host):
ret = os.system('ping -c 3 -t 3 -n -q {} > /dev/null'.format(host))
if ret == 0:
return True
return False
@i3130002
Copy link

i3130002 commented Oct 4, 2023

def is_alive(host):
    return os.system(f"ping -c 3 -t 3 -n -q {host} > /dev/null") == 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment