-
-
Notifications
You must be signed in to change notification settings - Fork 342
/
snoopnetworktest.py
executable file
·57 lines (50 loc) · 2.38 KB
/
snoopnetworktest.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
#! /usr/bin/env python3
# Copyright (c) 2020 Snoop Project <[email protected]>
"Самотестирование сети"
import speedtest
from rich.panel import Panel
from rich.style import Style as STL
from rich.console import Console
console2 = Console()
def nettest():
with console2.status("[cyan] Ожидайте, идёт самотестирование сети..."):
servers = []
threads = None
try:
s = speedtest.Speedtest(secure=True)
s.get_servers(servers)
s.get_best_server()
s.download(threads=threads)
s.upload(threads=threads)
a = s.results.dict()
d = round(a.get("download") / 1_000_000, 2)
u = round(a.get("upload") / 1_000_000, 2)
p = round(a.get("ping"))
c = a.get("client")
# Скорость загрузки.
try:
if d < 3: d = f"Download: [bold red]{d}[/bold red] Мбит/с"
elif 3 <= d <= 5.5: d = f"Download: [yellow]{d}[/yellow] Мбит/с"
elif d > 5.5: d = f"Download: [bold green]{d}[/bold green] Мбит/с"
except:
d = f"Download: [bold red]Сбой[/bold red]"
# Скорость выгрузки.
try:
if u < 0.8: u = f"Upload: [bold red]{u}[/bold red] Мбит/с"
elif 0.8 <= u <= 1.5: u = f"Upload: [yellow]{u}[/yellow] Мбит/с"
elif u > 1.5: u = f"Upload: [bold green]{u}[/bold green] Мбит/с"
except:
u = f"Upload: [bold red]Сбой[/bold red]"
# Ping.
try:
if p >= 250: p = f"Ping: [bold red]{p}[/bold red] мс"
elif 60 <= p < 250: p = f"Ping: [yellow]{p}[/yellow] мс"
elif p < 60: p = f"Ping: [bold green]{p}[/bold green] мс"
except:
p = f"Ping: [bold red]Сбой[/bold red]"
# Результат.
console2.print(Panel.fit(f"{d}\n{u}\n{p}\n\nВаш ip: {c.get('ip')}\nПровайдер: {c.get('isp')}\nЛокация: {c.get('country')}",
title="🌐 Тест сети", style=STL(color="cyan")))
console2.log("[cyan]--> завершен")
except Exception:
console2.print(f"[bold red]Аномалии в сети.\nТест будет пропущен...")