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