mercredi 7 novembre 2018

Ping Script - if response

I am just trying to put together a simple server up/down script as I have just started to learn python.

Below is the script... but I can't get it to output the Server Down section of code. the if response == 0 I'm guessing is picking up the "Destination Unreachable" response and is making a false positive.

what can I do to get around this?

# Server up/down Script

import os

hostname1 = input (" Please Enter IP Address: ")

response = os.system("echo ping -a -c 1 " + hostname1)

#and then check the response...
if response == 0: # This will check the host repeatedly
    print (hostname1, '\033[1;32m [ **SERVER ALIVE** ] \033[1;m')
    # As long as the server is up it will print the UP response in green text
else:
    print(hostname1, '[ **SERVER DOWN** ]')
print( 30 * "-")

Aucun commentaire:

Enregistrer un commentaire