From 4bcf772212adf57487f9d92a41dde2bee8e92f4b Mon Sep 17 00:00:00 2001 From: clt Date: Thu, 27 Apr 2023 09:02:26 +0200 Subject: [PATCH] First commit --- README.md | 2 -- hosts | 4 ++++ main.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 hosts create mode 100644 main.py diff --git a/README.md b/README.md index 21bd30c..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,2 +0,0 @@ -# ping_plong - diff --git a/hosts b/hosts new file mode 100644 index 0000000..c6f96ca --- /dev/null +++ b/hosts @@ -0,0 +1,4 @@ +google.com +gt.se +127.0.0.1 +googoogogogllglel.com \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..95ffa0c --- /dev/null +++ b/main.py @@ -0,0 +1,32 @@ +import subprocess +import platform + +print ("PING SCANNER") + +#Sätt parameter n om Linux och c om Windows +param = '-n' if platform.system().lower()=='windows' else '-c' + +#Ping function +def ping(host): + command = ["ping", param, "1", host] + return subprocess.call(command, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) == 0 + +#Pinga enskild host +host = "google.com" + +if ping(host): + print("Ping successfull!") +else: + print("Ping unsuccessfull") + +#En lista för hostar som ska pingas +host_list = ["google.com", "gt.se", "amazon.com"] + +#Loop som pingar varje host i listan +for host in host_list: + print(host) + ping(host) + if ping(host): + print("Ping successfull!") + else: + print("Ping unsuccessfull") \ No newline at end of file