Skip to content

Commit

Permalink
Added nameservers pre-flight check, issue #543 (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
spaolo authored Oct 3, 2024
1 parent d80ce74 commit fdb4e4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/source/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ The full set of configuration options are:
- `reverse_dns_map_url` - Overrides the default download URL for the reverse DNS map
- `nameservers` - str: A comma separated list of
DNS resolvers (Default: `[Cloudflare's public resolvers]`)
- `dns_test_address` - str: a dummy address used for DNS pre-flight checks
(Default: 1.1.1.1)
- `dns_timeout` - float: DNS timeout period
- `debug` - bool: Print debugging messages
- `silent` - bool: Only print errors (Default: `True`)
Expand Down
22 changes: 19 additions & 3 deletions parsedmarc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from parsedmarc.mail.graph import AuthMethod

from parsedmarc.log import logger
from parsedmarc.utils import is_mbox
from parsedmarc.utils import is_mbox, get_reverse_dns

formatter = logging.Formatter(
fmt='%(levelname)8s:%(filename)s:%(lineno)d:%(message)s',
Expand Down Expand Up @@ -447,6 +447,7 @@ def process_reports(reports_):
smtp_tls_json_filename=args.smtp_tls_json_filename,
smtp_tls_csv_filename=args.smtp_tls_csv_filename,
nameservers=args.nameservers,
dns_test_address='1.1.1.1',
silent=args.silent,
warnings=args.warnings,
dns_timeout=args.dns_timeout,
Expand Down Expand Up @@ -599,10 +600,25 @@ def process_reports(reports_):
if "smtp_tls_csv_filename" in general_config:
opts.smtp_tls_csv_filename = general_config[
"smtp_tls_csv_filename"]
if "nameservers" in general_config:
opts.nameservers = _str_to_list(general_config["nameservers"])
if "dns_timeout" in general_config:
opts.dns_timeout = general_config.getfloat("dns_timeout")
if "dns_test_address" in general_config:
opts.dns_test_address=general_config["dns_test_address"]
if "nameservers" in general_config:
opts.nameservers = _str_to_list(general_config["nameservers"])
# nameservers pre-flight check
dummy_hostname=None
try:
dummy_hostname=get_reverse_dns(opts.dns_test_address,
nameservers=opts.nameservers,
timeout=opts.dns_timeout)
except Exception as ns_error:
logger.critical("DNS pre-flight check failed: {}".format(ns_error))
exit(-1)
if not dummy_hostname:
logger.critical("DNS pre-flight check failed: no PTR record for "
"{} from {}".format(opts.dns_test_address,opts.nameservers))
exit(-1)
if "save_aggregate" in general_config:
opts.save_aggregate = general_config["save_aggregate"]
if "save_forensic" in general_config:
Expand Down

0 comments on commit fdb4e4c

Please sign in to comment.