-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomain_validator.py
More file actions
88 lines (67 loc) · 2.18 KB
/
domain_validator.py
File metadata and controls
88 lines (67 loc) · 2.18 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
77
78
79
80
81
82
83
84
85
86
87
"""
Domain validation module for ESDAR-Checker
@author Merlin von der Weide
@version 2.0.0
@date 2025
"""
import os
import sys
import socket
from typing import List
from validators import domain as validate_domain
from terminal_message_handler import print_error, print_warning
def validate_provided_domains(domains: List[str]) -> bool:
"""
Validate a list of domains.
Args:
domains: List of domain strings to validate
Returns:
True if all domains are valid, False otherwise
"""
invalid_domains = []
for domain in domains:
if not validate_domain(domain):
invalid_domains.append(domain)
if invalid_domains:
for invalid in invalid_domains:
print_warning(f"Invalid domain format: {invalid}")
return False
return True
def validate_args(args) -> bool:
"""
Validate command-line arguments.
Args:
args: Parsed command-line arguments
Returns:
True if arguments are valid, False otherwise
"""
domain_arg_valid = True
domain_file_arg_valid = True
# Validate single domain if provided
if args.domain:
domain_arg_valid = validate_domain(args.domain)
if not domain_arg_valid:
print_warning(f"Domain '{args.domain}' is not valid. Is it formatted correctly?")
# Validate domain file if provided
if args.domains_file:
domain_file_arg_valid = os.path.isfile(args.domains_file)
if not domain_file_arg_valid:
print_warning(f"Domain file '{args.domains_file}' does not exist or is not accessible.")
valid_args = domain_arg_valid and domain_file_arg_valid
if not valid_args:
print_error("Arguments are invalid. Please check your input.")
sys.exit(1)
return valid_args
def check_domain_exists(domain: str) -> bool:
"""
Check if a domain exists by attempting DNS resolution.
Args:
domain: Domain name to check
Returns:
True if domain resolves, False otherwise
"""
try:
socket.gethostbyname(domain)
return True
except (socket.gaierror, socket.error):
return False