2020-08-29 06:13:59 -07:00
|
|
|
def ui(program, args):
|
|
|
|
from .db import RespoDB
|
|
|
|
from .dns import main
|
|
|
|
from .structs import Options
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
from asyncio import run
|
|
|
|
import respodns.checks as chk
|
|
|
|
|
|
|
|
name = "respodns6"
|
2020-08-29 06:34:46 -07:00
|
|
|
desc = name + ": test and log DNS records"
|
|
|
|
parser = ArgumentParser(name, description=desc)
|
2020-08-29 06:13:59 -07:00
|
|
|
|
|
|
|
# TODO: support multiple paths. nargs="+", iterate with pooling?
|
2020-08-29 06:34:46 -07:00
|
|
|
desc = "a path to a file containing IPv4 addresses which host DNS servers"
|
|
|
|
parser.add_argument("path", metavar="file-path", help=desc)
|
2020-08-29 06:13:59 -07:00
|
|
|
|
2020-08-29 06:34:46 -07:00
|
|
|
parser.add_argument("--database", help="specify database for logging")
|
2020-08-29 06:13:59 -07:00
|
|
|
|
|
|
|
a = parser.parse_args(args)
|
|
|
|
|
|
|
|
checks = []
|
|
|
|
checks += chk.first
|
|
|
|
checks += chk.likely
|
|
|
|
|
|
|
|
opts = Options()
|
|
|
|
opts.dry = a.database is None
|
|
|
|
opts.early_stopping = opts.dry
|
|
|
|
|
|
|
|
if a.database is not None:
|
|
|
|
if a.database.startswith("sqlite:"):
|
|
|
|
uri = a.database
|
|
|
|
else:
|
|
|
|
uri = "sqlite:///" + a.database
|
|
|
|
|
|
|
|
def runwrap(db, debug=False):
|
|
|
|
if debug:
|
|
|
|
import logging
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
run(main(db, a.path, checks, opts), debug=True)
|
|
|
|
else:
|
|
|
|
run(main(db, a.path, checks, opts))
|
|
|
|
|
|
|
|
if opts.dry:
|
|
|
|
runwrap(None)
|
|
|
|
else:
|
|
|
|
# log to a database.
|
|
|
|
db = RespoDB(uri, create=True)
|
|
|
|
with db: # TODO: .open and .close methods for manual invocation.
|
|
|
|
with db.execution as execution: # TODO: clean up this interface.
|
|
|
|
opts.execution = execution
|
|
|
|
runwrap(db)
|