gcpdiag.queries.dns

Queries related to DNS.
def find_dns_records(domain: str) -> Set:
25def find_dns_records(domain: str) -> Set:
26  """Resolves DNS records for a given domain and returns a set of IP addresses.
27
28  Returns an empty set if any error occurs. Logs errors using logging.info.
29  """
30  try:
31    answer = dns.resolver.resolve_name(domain)
32    return set(answer.addresses())
33  except dns.resolver.NoAnswer:
34    logging.info("Error: No records found for domain: %s", domain)
35    return set()
36  except dns.resolver.NXDOMAIN:
37    logging.info("Error: Invalid domain: %s", domain)
38    return set()
39  except dns.resolver.Timeout:
40    logging.info("Error: DNS resolution timed out for domain: %s", domain)
41    return set()
42  except dns.name.EmptyLabel:
43    logging.info("Error: Empty A/AAAA record for domain: %s", domain)
44    return set()
45  except dns.name.LabelTooLong:
46    logging.info("Error: Invalid record label too long for domain: %s", domain)
47    return set()
48  except dns.name.NameTooLong:
49    logging.info("Error: DNS name too long for domain: %s", domain)
50    return set()
51  except dns.resolver.NoNameservers:
52    logging.info("Error: No nameservers found for domain: %s", domain)
53    return set()
54  except dns.exception.DNSException as e:  # Catch any other DNS exception
55    logging.info("Error: An unexpected DNS error occurred: %s", str(e))
56    return set()

Resolves DNS records for a given domain and returns a set of IP addresses.

Returns an empty set if any error occurs. Logs errors using logging.info.