|
@@ -1,4 +1,7 @@
|
|
-import os, platform, webbrowser, json
|
|
|
|
|
|
+import os
|
|
|
|
+import platform
|
|
|
|
+import webbrowser
|
|
|
|
+import json
|
|
import subprocess as sp
|
|
import subprocess as sp
|
|
import datetime as dt
|
|
import datetime as dt
|
|
from jinja2 import Environment, FileSystemLoader
|
|
from jinja2 import Environment, FileSystemLoader
|
|
@@ -9,49 +12,49 @@ env = Environment(
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
def get_state_ping(ip_address):
|
|
def get_state_ping(ip_address):
|
|
if platform.system() in 'Linux':
|
|
if platform.system() in 'Linux':
|
|
command = "ping -w 1 -c 1 %s"
|
|
command = "ping -w 1 -c 1 %s"
|
|
else:
|
|
else:
|
|
command = "ping -n 1 %s"
|
|
command = "ping -n 1 %s"
|
|
-
|
|
|
|
|
|
+
|
|
try:
|
|
try:
|
|
status, result = sp.getstatusoutput(
|
|
status, result = sp.getstatusoutput(
|
|
command % (ip_address)
|
|
command % (ip_address)
|
|
)
|
|
)
|
|
except ValueError:
|
|
except ValueError:
|
|
- return 1
|
|
|
|
-
|
|
|
|
|
|
+ return 1
|
|
|
|
+
|
|
return status
|
|
return status
|
|
|
|
|
|
|
|
+
|
|
def ip_check(ip: str, count: int) -> dict:
|
|
def ip_check(ip: str, count: int) -> dict:
|
|
pbar = tqdm()
|
|
pbar = tqdm()
|
|
pbar.reset(total=count)
|
|
pbar.reset(total=count)
|
|
-
|
|
|
|
|
|
+
|
|
count_good_ping = 0
|
|
count_good_ping = 0
|
|
- time = dt.datetime.now().strftime('%H:%M:%S')
|
|
|
|
-
|
|
|
|
|
|
+ time = dt.datetime.now().strftime('%H:%M:%S')
|
|
|
|
+
|
|
for _ in range(count):
|
|
for _ in range(count):
|
|
if get_state_ping(ip) == 0:
|
|
if get_state_ping(ip) == 0:
|
|
count_good_ping += 1
|
|
count_good_ping += 1
|
|
-
|
|
|
|
pbar.update()
|
|
pbar.update()
|
|
-
|
|
|
|
|
|
+
|
|
pbar.refresh()
|
|
pbar.refresh()
|
|
-
|
|
|
|
|
|
+
|
|
return {
|
|
return {
|
|
"ip": ip,
|
|
"ip": ip,
|
|
"good_ping": count_good_ping,
|
|
"good_ping": count_good_ping,
|
|
"time": time
|
|
"time": time
|
|
- }
|
|
|
|
-
|
|
|
|
-def start(params: dict):
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def main(params: dict):
|
|
list_result = []
|
|
list_result = []
|
|
for ip in params.get('list_ip'):
|
|
for ip in params.get('list_ip'):
|
|
print(F"Check ip: {ip}")
|
|
print(F"Check ip: {ip}")
|
|
list_result.append(ip_check(ip, int(params.get('count'))))
|
|
list_result.append(ip_check(ip, int(params.get('count'))))
|
|
-
|
|
|
|
|
|
+
|
|
template = env.get_template("template.html")
|
|
template = env.get_template("template.html")
|
|
render_template = template.render({
|
|
render_template = template.render({
|
|
"count": params.get('count'),
|
|
"count": params.get('count'),
|
|
@@ -59,10 +62,11 @@ def start(params: dict):
|
|
"date": dt.date.today(),
|
|
"date": dt.date.today(),
|
|
})
|
|
})
|
|
|
|
|
|
- html_path = os.path.join(os.path.dirname(__file__), F"report_{dt.datetime.today().timestamp()}.html")
|
|
|
|
|
|
+ html_path = os.path.join(os.path.dirname(
|
|
|
|
+ __file__), F"report_{dt.datetime.today().timestamp()}.html")
|
|
with open(html_path, 'w') as f:
|
|
with open(html_path, 'w') as f:
|
|
f.write(render_template)
|
|
f.write(render_template)
|
|
-
|
|
|
|
|
|
+
|
|
webbrowser.open(F"file://{html_path}", new=2)
|
|
webbrowser.open(F"file://{html_path}", new=2)
|
|
|
|
|
|
|
|
|
|
@@ -72,4 +76,4 @@ if __name__ == "__main__":
|
|
with open('settings.json') as f:
|
|
with open('settings.json') as f:
|
|
data_from_json = json.load(f)
|
|
data_from_json = json.load(f)
|
|
|
|
|
|
- start(data_from_json)
|
|
|
|
|
|
+ main(data_from_json)
|