-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicmp_monitoring.py
75 lines (62 loc) · 2.62 KB
/
icmp_monitoring.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import time
import threading
import subprocess
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import rcParams
import arabic_reshaper
from bidi.algorithm import get_display
import tkinter as tk
from tkinter import simpledialog
rcParams['font.family'] = 'Tahoma'
rcParams['font.size'] = 12
def get_ips():
root = tk.Tk()
root.withdraw() # مخفی کردن پنجره اصلی
ip_input = simpledialog.askstring("Input", "لطفاً IPها را وارد کنید، آنها را با کاما جدا کنید:")
if ip_input:
return ip_input.split(",")
else:
return []
ips = get_ips()
if not ips:
print("هیچ IP وارد نشد. برنامه خاتمه یافت.")
exit(1)
def ping_ips():
while True:
responses = []
for ip in ips:
response = subprocess.run(["ping", "-n", "1", "-w", "500", ip],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
creationflags=subprocess.CREATE_NO_WINDOW)
responses.append(response.returncode == 0)
ping_results.append(responses)
if len(ping_results) > max_display_time:
ping_results.pop(0)
time.sleep(1)
fig, ax = plt.subplots()
ping_results = []
max_display_time = 100 # حداکثر تعداد نقاط زمانی که در نمودار نمایش داده میشود
def update_graph(i):
ax.clear()
# استفاده از arabic_reshaper و bidi برای پشتیبانی از حروف فارسی و عربی
xlabel = arabic_reshaper.reshape("زمان (ثانیه)")
ylabel = arabic_reshaper.reshape("وضعیت (پاسخ دارد/ندارد)")
xlabel = get_display(xlabel)
ylabel = get_display(ylabel)
ax.set_title("PHOENIX Monitoring", fontname='Tahoma', loc='right')
ax.set_xlabel(xlabel, fontname='Tahoma', loc='right')
ax.set_ylabel(ylabel, fontname='Tahoma', loc='top')
times = list(range(len(ping_results)))
for idx, ip in enumerate(ips):
ax.plot(times, [result[idx] for result in ping_results], label=ip)
ax.set_xlim(left=max(0, len(ping_results) - max_display_time), right=len(ping_results))
ax.set_ylim(-0.1, 1.1)
labels = [get_display(arabic_reshaper.reshape(ip)) for ip in ips]
ax.legend(labels=labels, prop={'family': 'Tahoma'}, loc='upper right')
ping_thread = threading.Thread(target=ping_ips)
ping_thread.daemon = True
ping_thread.start()
ani = animation.FuncAnimation(fig, update_graph, interval=500, save_count=100, cache_frame_data=False)
plt.show()