forked from Diramid/hey403
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhey403.py
More file actions
76 lines (61 loc) · 1.97 KB
/
Copy pathhey403.py
File metadata and controls
76 lines (61 loc) · 1.97 KB
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
76
import argparse
from rich.console import Console
from rich.progress import Progress
from src.cli.parser import build_parser
from src.dns import test_dns_with_custom_ip
from src.table import create_table
from src.dns_servers import DNS_SERVERS
from concurrent.futures import ThreadPoolExecutor, as_completed
def test_dns(dns, url):
dns_name = dns["name"]
preferred_dns = dns["preferred"]
alternative_dns = dns["alternative"]
status, response_time = test_dns_with_custom_ip(url, preferred_dns)
status_message = (
"[green]Success[/green]" if status != "Failed" else "[red]Failed[/red]"
)
response_time_display = (
f"{response_time:.4f}" if response_time < float('inf') else "N/A"
)
return (
dns_name,
preferred_dns,
alternative_dns,
status_message,
response_time_display,
)
def main():
parser = build_parser()
args = parser.parse_args()
console = Console()
table = create_table()
with Progress() as progress:
task = progress.add_task(
"[cyan]Testing DNS servers...", total=len(DNS_SERVERS)
)
with ThreadPoolExecutor(
max_workers=min(32, len(DNS_SERVERS))
) as executor:
futures = {
executor.submit(test_dns, dns, args.url): dns
for dns in DNS_SERVERS
}
for future in as_completed(futures):
(
dns_name,
preferred_dns,
alternative_dns,
status_message,
response_time_display,
) = future.result()
table.add_row(
dns_name,
preferred_dns,
alternative_dns,
status_message,
response_time_display,
)
progress.update(task, advance=1)
console.print(table)
if __name__ == "__main__":
main()