Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions ping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import subprocess
import platform
import subprocess
import threading
import time

results = {}

def ping(ip):
"""
Expand All @@ -18,17 +22,23 @@ def ping(ip):
# We will check if the output contains the string '0% packet loss' or not
output_list = output.split(packet_loss_string)
if len(output_list) > 1:
results[ip] = "UP"
return "UP"
else:
results[ip] = "DOWN"
return "DOWN"


def ping_all(ips):
"""
pings all ips and returns a dictionary
"""
results = {}
threads = []
for ip in ips:
result = ping(ip)
results[ip] = result
return results
thread = threading.Thread(target=ping, args=(ip,))
threads.append(thread)
thread.start()
time.sleep(.2)
for thread in threads:
thread.join()
return results