-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpingtest.py
More file actions
34 lines (27 loc) · 717 Bytes
/
Copy pathpingtest.py
File metadata and controls
34 lines (27 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
from datetime import datetime
import time
import threading #implements threading in Python
start = time.time()
with open ("device") as file:
dump = file.read()
dump = dump.splitlines()
print(dump)
def ping(ip):
res = os.popen(f"ping {ip} -c 3").read()
if "100% packet loss" in res:
print(f"down {ip} ")
else:
print(f"up {ip}")
threads = list()
for ip in dump:
th = threading.Thread(target=ping, args=(ip,))
threads.append(th) # appending the thread to the list
# starting the threads
for th in threads:
th.start()
# waiting for the threads to finish
for th in threads:
th.join()
end = time.time()
print(f'Total excecution time: {end-start}')