Skip to content

Commit b011fae

Browse files

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

checks/caa/retrieval.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from dataclasses import dataclass, field, InitVar
22
from typing import Optional, Iterable
33

4+
import dns
45
from dns.rdtypes.ANY.CAA import CAA
56
from dns.resolver import NoAnswer, NXDOMAIN, LifetimeTimeout, NoNameservers
67

@@ -57,7 +58,7 @@ def retrieve_parse_caa(target_domain: str) -> CAAEvaluation:
5758
"""
5859
try:
5960
canonical_name, rrset = dns_resolve_caa(target_domain)
60-
except (NoAnswer, NXDOMAIN, LifetimeTimeout, NoNameservers):
61+
except (NoNameservers, NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
6162
return CAAEvaluation(caa_found=False)
6263

6364
return CAAEvaluation(caa_found=True, canonical_name=canonical_name, caa_records=rrset)

checks/tasks/dnssec.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import sys
44
from collections import OrderedDict
55

6+
import dns
67
import pythonwhois
78
from celery import shared_task
89
from celery.exceptions import SoftTimeLimitExceeded
910
from django.conf import settings
1011
from django.core.cache import cache
1112
from django.db import transaction
1213

13-
from dns.resolver import NoNameservers
14+
from dns.resolver import NoNameservers, LifetimeTimeout, NoAnswer
1415

1516
from checks import categories, scoring
1617
from checks.models import DnssecStatus, DomainTestDnssec, MailTestDnssec, MxStatus
@@ -372,7 +373,7 @@ def dnssec_status(domain, mx_status, score_secure, score_insecure, score_bogus,
372373
log.info(f"requesting SOA for {domain=} with {mx_status=}")
373374
answer_dnssec_status = dns_resolve_soa(domain, raise_on_no_answer=False)
374375
status, score = status_mapping[answer_dnssec_status]
375-
except NoNameservers:
376+
except (NoNameservers, NoAnswer, NoNameservers, LifetimeTimeout, dns.name.EmptyLabel):
376377
status = DnssecStatus.dnserror.value
377378
score = score_error
378379

checks/tasks/ipv6.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from django.core.cache import cache
1414
from django.db import transaction
1515
import dns
16-
from dns.resolver import NoAnswer, NXDOMAIN, LifetimeTimeout
16+
from dns.resolver import NoAnswer, NXDOMAIN, LifetimeTimeout, NoNameservers
1717

1818
from checks import categories, scoring
1919
from checks.http_client import http_get_af, response_content_chunk
@@ -354,14 +354,14 @@ def get_domain_results(
354354
"""
355355
try:
356356
v6 = dns_resolve_aaaa(domain)
357-
except (NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
357+
except (NoNameservers, NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
358358
v6 = []
359359
v6 = remove_ipv4_mapped_v6(v6)
360360
log.debug("V6 resolve: %s" % v6)
361361
v6_good, v6_bad, v6_ports = test_connectivity(v6, socket.AF_INET6, sock_type, ports, is_ns, test_domain)
362362
try:
363363
v4 = dns_resolve_a(domain)
364-
except (NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
364+
except (NoNameservers, NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
365365
v4 = []
366366
log.debug("V4 resolve: %s" % v4)
367367
v4_good, v4_bad, v4_ports = test_connectivity(v4, socket.AF_INET, sock_type, ports, is_ns, test_domain)

checks/tasks/shared.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ def do_resolve_single_a_aaaa(qname):
184184
af_ip_pairs = []
185185
try:
186186
ip4 = dns_resolve_a(qname)
187-
except (NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
187+
except (NoNameservers, NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
188188
ip4 = []
189189
if len(ip4) > 0:
190190
af_ip_pairs.append((socket.AF_INET, ip4[0]))
191191
try:
192192
ip6 = dns_resolve_aaaa(qname)
193-
except (NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
193+
except (NoNameservers, NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
194194
ip6 = []
195195
if len(ip6) > 0:
196196
af_ip_pairs.append((socket.AF_INET6, ip6[0]))
@@ -202,13 +202,13 @@ def do_resolve_all_a_aaaa(qname):
202202
af_ip_pairs = []
203203
try:
204204
ip4 = dns_resolve_a(qname)
205-
except (NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
205+
except (NoNameservers, NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
206206
ip4 = []
207207
for ip in ip4:
208208
af_ip_pairs.append((socket.AF_INET, ip))
209209
try:
210210
ip6 = dns_resolve_aaaa(qname)
211-
except (NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
211+
except (NoNameservers, NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
212212
ip6 = []
213213
for ip in ip6:
214214
af_ip_pairs.append((socket.AF_INET6, ip))
@@ -238,13 +238,13 @@ def do_resolve_ns(qname: str) -> tuple[list[str], str]:
238238
"""
239239
try:
240240
ns_list = dns_resolve_ns(qname)
241-
except (NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
241+
except (NoNameservers, NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
242242
ns_list = []
243243
next_label = qname
244244
while not ns_list and "." in next_label:
245245
try:
246246
ns_list = dns_resolve_ns(next_label)
247-
except (NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
247+
except (NoNameservers, NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
248248
ns_list = []
249249
next_label = next_label[next_label.find(".") + 1 :]
250250

@@ -276,7 +276,7 @@ def resolve_dane(port, dname, check_nxdomain=False):
276276
data = [(rr.usage, rr.selector, rr.mtype, binascii.hexlify(rr.cert).decode("ascii")) for rr in rrset]
277277
except NXDOMAIN:
278278
return {"nxdomain": True}
279-
except (NoAnswer, NoNameservers, LifetimeTimeout, dns.name.EmptyLabel):
279+
except (NoNameservers, NoAnswer, NoNameservers, LifetimeTimeout, dns.name.EmptyLabel):
280280
data = None
281281
dnssec_status = None
282282
return {

interface/views/shared.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from datetime import datetime
66
from urllib.parse import urlparse
77

8+
import dns
89
import idna
910
import yaml
1011
from celery import shared_task
@@ -18,7 +19,7 @@
1819
from django.utils.http import url_has_allowed_host_and_scheme
1920
from django.utils.translation import gettext as _
2021
from dns.rdatatype import RdataType
21-
from dns.resolver import NXDOMAIN, NoAnswer
22+
from dns.resolver import NXDOMAIN, NoAnswer, LifetimeTimeout, NoNameservers
2223
from dns.exception import Timeout
2324

2425
from checks.resolver import dns_resolve, dns_resolve_soa
@@ -273,7 +274,7 @@ def get_valid_domain_web(dname, timeout=5):
273274
try:
274275
dns_resolve(dname, qtype)
275276
return dname
276-
except (NoAnswer, NXDOMAIN, Timeout):
277+
except (NoNameservers, NoAnswer, NXDOMAIN, LifetimeTimeout, dns.name.EmptyLabel):
277278
pass
278279
log.debug(f"{dname}: Could not retrieve A/AAAA record")
279280
return None

0 commit comments

Comments
 (0)