import os # Device or address to ping hostname = "www.google.com" #example response = os.system("ping -c 1 " + hostname) #Check the response... if response == 0: print (hostname, 'is up!') else: print (hostname, 'is down!')