-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.py
More file actions
86 lines (75 loc) · 2.38 KB
/
Copy pathcli.py
File metadata and controls
86 lines (75 loc) · 2.38 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
#!/usr/bin/env python3
"""
Rangebuster CLI - Command line interface for searching CIDRs.
"""
import argparse
import time
from loguru import logger
from rangebuster import search_cidrs, __version__
from rangebuster.common.utils import get_duration, configure_logging
def main():
"""Main CLI function."""
parser = argparse.ArgumentParser(
prog="rangebuster",
description="Search RIR and ARIN databases for keywords to find CIDR ranges.",
epilog="Example: rangebuster tesla,solarcity -s -o results.json"
)
parser.add_argument(
"keywords",
help="Keywords to search for. Separate multiple keywords with commas or provide a file path ending with .txt"
)
parser.add_argument(
"-s", "--strict",
action="store_true",
help="Perform strict keyword matching (exact word boundaries)"
)
parser.add_argument(
"-nc", "--no_cache",
action="store_true",
help="Clear the cache folder (where databases are stored)"
)
parser.add_argument(
'-o', '--output',
type=str,
default=None,
help='Output filename (should end with .json)'
)
parser.add_argument(
'-v', '--verbose',
action='store_true',
help='Enable verbose logging (DEBUG level)'
)
parser.add_argument(
'--version',
action='version',
version=f'rangebuster {__version__}'
)
args = parser.parse_args()
# Configure logging based on verbose argument
configure_logging(verbose=args.verbose)
# Perform the search
start_time = time.time()
try:
results = search_cidrs(
keywords=args.keywords,
strict=args.strict,
output_file=args.output,
clear_cache=args.no_cache,
verbose=args.verbose
)
end_time = time.time()
finished = get_duration(start_time, end_time)
logger.warning(f"Finished in {finished}")
# Print summary
if results:
logger.warning(f"Found {len(results)} CIDR ranges")
else:
logger.warning("No CIDR ranges found")
except KeyboardInterrupt:
logger.warning("Search interrupted by user")
except Exception as e:
logger.error(f"An error occurred: {e}")
return 1
return 0
if __name__ == "__main__":
exit(main())