From 1dadeefecd503f086d6ca8e903f99ddf12ba9be6 Mon Sep 17 00:00:00 2001 From: Sarmadkubba <83927120+Sarmadkubba@users.noreply.github.com> Date: Sun, 5 Dec 2021 21:43:39 -0800 Subject: [PATCH 1/2] Update main.py --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 2fb474f..2f3c384 100644 --- a/main.py +++ b/main.py @@ -4,10 +4,11 @@ def print_program_info(): # TODO - Change your name - print("Server Automator v0.1 by Your Name") + print("Server Automator v0.1 by Sarmad") # This is the entry point to our program if __name__ == '__main__': print_program_info() # TODO - Create a Server object - # TODO - Call Ping method and print the results \ No newline at end of file + # TODO - Call Ping method and print the results + ec2Server = server.Server("13.58.111.80") From 8968097db0f79d16936b337d4afd7f7aa5d7ccd6 Mon Sep 17 00:00:00 2001 From: Sarmadkubba <83927120+Sarmadkubba@users.noreply.github.com> Date: Sun, 5 Dec 2021 21:48:22 -0800 Subject: [PATCH 2/2] Update Server.py --- Server.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Server.py b/Server.py index cb8697c..1bc48a1 100644 --- a/Server.py +++ b/Server.py @@ -7,4 +7,22 @@ def __init__(self, server_ip): def ping(self): # TODO - Use os module to ping the server - return \ No newline at end of file + print("The Server IP is", self.server_ip) + #Get the location from where the Python script is run + filepath = os.path.dirname(os.path.abspath(__file__)) + #Set the working directory to the path where the python source code is + os.chdir(filepath) + #pingresult = os.path.join(filepath,"pingResults__.txt") + #Create a text file Name to store the Ping results + pingresult = "pingResults__.txt" + pingText = 'ping ' + (self.server_ip) + ' > ' + pingresult + print("Command sent to the OS system for the ping is: ", pingText) + response = os.system(pingText) + #A response of 0 is returned for a sucessfull server response + f = open(pingresult, "r") + if (response == 0): + print("Ping Successfull for the server", self.server_ip) + print(f.read()) + else: + print("Check the server - Unsuccessfull ping response for ", self.server_ip) + print(f.read())