-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomex.py
More file actions
145 lines (119 loc) · 4.41 KB
/
domex.py
File metadata and controls
145 lines (119 loc) · 4.41 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python3
"""
Domex - Domain availability checker using regex patterns.
Usage:
python domex.py "^[a-z]{2}[0-9]{3}\\.(com|net)$"
python domex.py "^[a-z]{2}[0-9]{3}\\.(com|net)$" --rate 5 --output available.txt
"""
import argparse
import sys
import time
from datetime import datetime
from pathlib import Path
from domain_generator import generate_domains, count_combinations
from whois_checker import WhoisChecker
__version__ = "1.0.0"
def format_time(seconds: float) -> str:
"""Format seconds into human-readable time."""
if seconds < 60:
return f"{seconds:.0f}s"
elif seconds < 3600:
return f"{seconds / 60:.1f}m"
else:
return f"{seconds / 3600:.1f}h"
def main():
parser = argparse.ArgumentParser(
description='Check domain availability using regex patterns',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog='''
Examples:
python domex.py "^[a-z]{2}[0-9]{3}\\.(com|net)$"
python domex.py "^[a-z]{3}\\.com$" --rate 10 --output found.txt
python domex.py "^[a-z]{2}[0-9]{2}\\.net$" --limit 100
'''
)
parser.add_argument('--version', '-v', action='version',
version=f'Domex {__version__}')
parser.add_argument('pattern', nargs='?', help='Regex pattern for domains')
parser.add_argument('--rate', type=float, default=5.0,
help='Requests per second (default: 5)')
parser.add_argument('--output', '-o', type=str,
help='Output file for available domains')
parser.add_argument('--limit', type=int,
help='Max domains to check')
parser.add_argument('--quiet', '-q', action='store_true',
help='Only show available domains')
args = parser.parse_args()
# Check if pattern is provided
if not args.pattern:
parser.print_help()
sys.exit(1)
# Count total combinations
try:
total = count_combinations(args.pattern)
except Exception as e:
print(f"Error parsing pattern: {e}")
sys.exit(1)
limit = args.limit or total
check_count = min(total, limit)
if not args.quiet:
print(f"Pattern: {args.pattern}")
print(f"Total combinations: {total:,}")
print(f"Checking: {check_count:,} domains")
print(f"Rate limit: {args.rate} req/s")
est_time = check_count / args.rate
print(f"Estimated time: {format_time(est_time)}")
print("-" * 50)
# Initialize checker
checker = WhoisChecker(rate_limit=args.rate)
# Open output file if specified
output_file = None
if args.output:
output_file = open(args.output, 'w')
# Track stats
checked = 0
available = 0
errors = 0
start_time = time.time()
try:
for domain in generate_domains(args.pattern):
if args.limit and checked >= args.limit:
break
result = checker.check_domain(domain)
checked += 1
if result.available:
available += 1
print(f"[AVAILABLE] {domain}")
if output_file:
output_file.write(f"{domain}\n")
output_file.flush()
elif result.error:
errors += 1
if not args.quiet:
print(f"[ERROR] {domain}: {result.error}")
else:
if not args.quiet:
# Show progress every 10 domains
if checked % 10 == 0:
elapsed = time.time() - start_time
rate = checked / elapsed if elapsed > 0 else 0
remaining = (check_count - checked) / rate if rate > 0 else 0
print(f"[{checked}/{check_count}] "
f"Found: {available} | "
f"Rate: {rate:.1f}/s | "
f"ETA: {format_time(remaining)}", end='\r')
except KeyboardInterrupt:
print("\n\nInterrupted by user.")
finally:
if output_file:
output_file.close()
# Final summary
elapsed = time.time() - start_time
print("\n" + "=" * 50)
print(f"Checked: {checked:,} domains in {format_time(elapsed)}")
print(f"Available: {available:,}")
print(f"Errors: {errors:,}")
if args.output:
print(f"Results saved to: {args.output}")
if __name__ == '__main__':
main()