def __ultradns_zone_info_response_handler(self, response): """ Handles the API response. Incorrect JSON parsing is allowed upto 20 times post which the script exits. :param response: Response object """ try: response_data = response.json() record_sets = response_data["rrSets"] except (ValueError, AttributeError) as err: if self.UH.incorrect_response_json_allowed > 0: self._logger.warning( "Unable to parse response JSON for zone " + self.zone_queried) self.UH.incorrect_response_json_allowed -= 1 else: self.APIH.handle_api_error( "Unable to parse response JSON for 20 zones: " + repr(err), self.UH.jobs_manager, ) else: for record in record_sets: dns_info = dict() # The ownerName could be either the FQDN or a relative domain name. # In case it is a FQDN it will end in '.' fqdn = record["ownerName"] + "." + self.zone_queried if record["ownerName"].endswith("."): fqdn = record["ownerName"][:-1] # A get_root_domain lookup is performed because UDNS supports sub-zones dns_info["zone"] = ZoneManager.get_root_domain( self.zone_queried) dns_info["fqdn"] = fqdn dns_info["type"] = record["rrtype"].split(" ")[0].lower() dns_info["status"] = "unknown" for dns in record["rdata"]: if dns_info["type"] in ["a", "ptr"]: try: if IPAddress(dns).is_private(): continue except AddrFormatError as err: self._logger.warning("For " + fqdn + " encountered: " + str(err)) continue if not (dns_info["type"] in ["soa", "txt" ]) and dns.endswith("."): dns = dns[:-1] dns_info["value"] = dns dns_info["created"] = datetime.now() self.DNS_MGR.insert_record(dns_info.copy(), self.UH.source) self.UH.set_offset(response_data["resultInfo"])
def extract_rdns_info(self, ip): """ Extract RDNS domain and zone information from the IP address """ rnds_value = self.find_reverse_dns(ip) if rnds_value is None: return "", None if self._ZONES is None: self._ZONES = ZoneManager.get_distinct_zones(self.mongo_connector) rdns_zone = ZoneManager.get_root_domain(rnds_value, None) return rnds_value, rdns_zone