forked from wichmannpas/VersionInferrer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_sites.py
executable file
·53 lines (43 loc) · 1.92 KB
/
scan_sites.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
#!/usr/bin/env python3
import logging
import os
from argparse import ArgumentParser, Namespace
from base.utils import clean_path_name
from scanning.scanner import Scanner
def scan(arguments: Namespace):
"""Scan sites."""
scanner = Scanner(arguments.identifier)
if arguments.concurrent:
scanner.concurrent = arguments.concurrent
if arguments.log_dir:
os.makedirs(arguments.log_dir, exist_ok=True)
logging.basicConfig(
filename=os.path.join(arguments.log_dir, clean_path_name(arguments.identifier)),
format='%(asctime)-15s: %(message)s',
level=logging.INFO)
if arguments.persist_resources:
# must not exist or be an existing *directory*
assert os.path.isdir(arguments.persist_resources) or \
not os.path.exists(arguments.persist_resources), 'invalid persist path'
scanner.persist_resources = arguments.persist_resources
urls = None
if arguments.urls_from_file:
with open(arguments.urls_from_file, 'r') as fh:
urls = fh.read().splitlines()
scanner.scan_sites(arguments.count, urls=urls, skip=arguments.skip)
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('count', type=int, default=1000)
parser.add_argument('--concurrent', '-c', type=int, default=80)
parser.add_argument('--skip', '-s', type=int, default=0)
parser.add_argument('--urls-from-file', type=str, help='Read newline-separated URLs from file instead of majestic million')
parser.add_argument('--identifier', '-i', type=str, help='An identifier for this scan.', required=True)
parser.add_argument(
'--persist-resources',
'-p',
help='Persist retrieved resources within the specified path for debugging purposes.')
parser.add_argument(
'--log-dir',
'-l',
help='Write log file with identifier as name within directory.')
scan(parser.parse_args())