Picks out the IP address and TTL from the answer response for each record.
191946
private static ADnsAnswer decodeDnsRecord(DnsRecord dnsRecord, boolean includeIpVersion) {

        if (dnsRecord == null) {
            return null;
        }

        LOG.trace("Attempting to decode DNS record [{}]", dnsRecord);

        /* Read data from DNS record response. The data is a binary representation of the IP address
         * IPv4 address: 32 bits, IPv6 address: 128 bits */
        byte[] ipAddressBytes;
        final DefaultDnsRawRecord dnsRawRecord = (DefaultDnsRawRecord) dnsRecord;
        try {
            final ByteBuf byteBuf = dnsRawRecord.content();
            ipAddressBytes = new byte[byteBuf.readableBytes()];
            int readerIndex = byteBuf.readerIndex();
            byteBuf.getBytes(readerIndex, ipAddressBytes);
        } finally {
            /* Must manually release references on dnsRawRecord object since the DefaultDnsRawRecord class
             * extends ReferenceCounted. This also releases the above ByteBuf, since DefaultDnsRawRecord is
             * the holder for it. */
            dnsRawRecord.release();
        }

        LOG.trace("The IP address has [{}] bytes", ipAddressBytes.length);

        InetAddress ipAddress;
        try {
            ipAddress = InetAddress.getByAddress(ipAddressBytes); // Takes care of correctly creating an IPv4 or IPv6 address.
        } catch (UnknownHostException e) {
            // This should not happen.
            LOG.error("Could not extract IP address from DNS entry [{}]. Cause [{}]", dnsRecord.toString(), ExceptionUtils.getRootCauseMessage(e));
            return null;
        }

        LOG.trace("The resulting IP address is [{}]", ipAddress.getHostAddress());

        final ADnsAnswer.Builder builder = ADnsAnswer.builder()
                                                     .ipAddress(ipAddress.getHostAddress())
                                                     .dnsTTL(dnsRecord.timeToLive());

        if (includeIpVersion) {
            builder.ipVersion(ipAddress instanceof Inet4Address ? IP_4_VERSION : IP_6_VERSION);
        }

        return builder.build();
    }
868689
def parse_routing_info(cls, records):
        
        if len(records) != 1:
            raise RoutingProtocolError("Expected exactly one record")
        record = records[0]
        routers = []
        readers = []
        writers = []
        try:
            servers = record["servers"]
            for server in servers:
                role = server["role"]
                addresses = []
                for address in server["addresses"]:
                    addresses.append(SocketAddress.parse(address, DEFAULT_PORT))
                if role == "ROUTE":
                    routers.extend(addresses)
                elif role == "READ":
                    readers.extend(addresses)
                elif role == "WRITE":
                    writers.extend(addresses)
            ttl = record["ttl"]
        except (KeyError, TypeError):
            raise RoutingProtocolError("Cannot parse routing info")
        else:
            return cls(routers, readers, writers, ttl)
872289
def get_default_values(data):
    """"""
    request = data.get('request')
    result = {}
    result['__datetime__'] = datetime.now()
    result['__ip_address__'] = request and get_ip(request) or '0.0.0.0'
    return result
908692
def _get_ids_from_ip(self, ip_address):  # pylint: disable=inconsistent-return-statements
        """"""
        try:
            # Does it look like an ip address?
            socket.inet_aton(ip_address)
        except socket.error:
            return []

        # Find the VS via ip address. First try public ip, then private
        results = self.list_instances(public_ip=ip_address, mask="id")
        if results:
            return [result['id'] for result in results]

        results = self.list_instances(private_ip=ip_address, mask="id")
        if results:
            return [result['id'] for result in results]
540039
def ip_info(self, ip, repository_ids=None):
        
        if not repository_ids:
            repository_ids = []
        repos = []
        for rid in repository_ids:
            repos.append({'id': rid})
        return self.raw_query('vuln', 'getIP', data={
            'ip': ip, 'repositories': repos})
455475
private String[] probeIps() {
        Set<String> ips = new TreeSet<String>();
        for (int i = 0; i < 32; ++i) {
            InetSocketAddress sa = new InetSocketAddress(_server, _port);
            ips.add(sa.getAddress().getHostAddress());
        }

        if (LOG.isDebugEnabled()) {
            StringBuffer sb = new StringBuffer();
            for (String ip : ips) {
                sb.append(ip);
                sb.append(" ");
            }
            LOG.debug(sb.toString());
        }

        return (String[]) ips.toArray(new String[0]);
    }
1207759
def get_mx_records(domain):
        
        import dns.resolver

        response = dns.resolver.query(domain, 'MX')

        mx_records = []
        for answer in response.answers:
            mx_records.append(MXRecord(priority=answer.preference, exchange=answer.exchange, domain=domain))

        return sorted(mx_records, key=lambda record: record.priority)
417075
def _decode_response(self, ip_address):
        
        # Reverse the IP, reassign the octets to integers
        vt, ts, days, rc = [int(o) for o in ip_address.split('.')[::-1]]

        # 127 reflects a valid query response, all others are errors
        if rc != 127:
            raise ValueError('Invalid Response Code: {}'.format(rc))

        # Build a list of visitor types since one IP can be multiple
        visitor_types = []
        if vt & COMMENT_SPAMMER:
            visitor_types.append(COMMENT_SPAMMER)
        if vt & HARVESTER:
            visitor_types.append(HARVESTER)
        if vt & SUSPICIOUS:
            visitor_types.append(SUSPICIOUS)

        # Return the response dictionary
        return {'days_since_last_activity': days if vt else None,
                'name': None if vt else SEARCH_ENGINES[ts],
                'threat_score': ts if vt else None,
                'type': visitor_types if vt else [SEARCH_ENGINE]}
474926
def _list_records_internal(self, identifier=None, rtype=None, name=None, content=None):
        """"""
        response = self._request_get_dns_zone()
        if 'records' in response:
            # Interpret empty string as None because zeep does so too
            content_check = content if content != "" else None
            name_check = self._relative_name(name)

            # Stringize the identifier to prevent any rtype differences
            identifier_check = str(
                identifier) if identifier is not None else None

            filtered_records = [
                record for record in response['records'] if (
                    identifier is None or str(
                        record['id']) == identifier_check) and (
                            rtype is None or record['type'] == rtype) and (
                                name is None or record['name'] == name_check) and (
                                    content is None or (
                                        'content' in record
                                        and record['content'] == content_check))]
            records = [self._create_response_record(
                filtered_record) for filtered_record in filtered_records]
        else:
            records = []
        return records
1018463
def sr(self, multi=0):
        """"""  # noqa: E501
        remain = self.res[:]
        sr = []
        i = 0
        while i < len(remain):
            s = remain[i]
            j = i
            while j < len(remain) - 1:
                j += 1
                r = remain[j]
                if r.answers(s):
                    sr.append((s, r))
                    if multi:
                        remain[i]._answered = 1
                        remain[j]._answered = 2
                        continue
                    del(remain[j])
                    del(remain[i])
                    i -= 1
                    break
            i += 1
        if multi:
            remain = [x for x in remain if not hasattr(x, "_answered")]
        return SndRcvList(sr), PacketList(remain)
375734
def _ttl(self):
        """"""
        return self.hlim if isinstance(self, scapy.layers.inet6.IPv6) else self.ttl
1034584
def get_ip_addresses():
        
        LOGGER.debug("IPAddressService.get_ip_addresses")
        args = {'http_operation': 'GET', 'operation_path': ''}
        response = IPAddressService.requester.call(args)
        ret = None
        if response.rc == 0:
            ret = []
            for ipAddress in response.response_content['ipAddresses']:
                ret.append(IPAddress.json_2_ip_address(ipAddress))
        elif response.rc != 404:
            err_msg = 'IPAddressService.get_ip_addresses - Problem while getting IP Address. ' \
                      'Reason: ' + str(response.response_content) + '-' + str(response.error_message) + \
                      " (" + str(response.rc) + ")"
            LOGGER.warning(err_msg)
        return ret
892997
def action_findip(reader, *args):
    """"""
    target_ips = set(args)
    for record in reader:
        if (record.srcaddr in target_ips) or (record.dstaddr in target_ips):
            print(record.to_message())
1126345
def _list_records(self, rtype=None, name=None, content=None):
        
        opts = {'domain': self._domain}
        if rtype is not None:
            opts['type'] = rtype.upper()
        if name is not None:
            opts['name'] = self._full_name(name)
        if content is not None:
            opts['content'] = content
        opts.update(self._auth)

        response = self._api.nameserver.info(opts)
        self._validate_response(
            response=response, message='Failed to get records')

        records = []
        if 'record' in response['resData']:
            for record in response['resData']['record']:
                processed_record = {
                    'type': record['type'],
                    'name': record['name'],
                    'ttl': record['ttl'],
                    'content': record['content'],
                    'id': record['id']
                }
                records.append(processed_record)

        return records
458139
def get_record_params(args):
    
    name, rtype, content, ttl, priority = (
        args.name, args.rtype, args.content, args.ttl, args.priority)
    return name, rtype, content, ttl, priority
786757
def _list_records(self, rtype=None, name=None, content=None):
        """"""
        records = []
        paginator = RecordSetPaginator(self.r53_client, self.domain_id)
        for record in paginator.all_record_sets():
            if rtype is not None and record['Type'] != rtype:
                continue
            if name is not None and record['Name'] != self._fqdn_name(name):
                continue
            if record.get('AliasTarget', None) is not None:
                record_content = [record['AliasTarget'].get('DNSName', None)]
            if record.get('ResourceRecords', None) is not None:
                record_content = [self._format_content(record['Type'], value['Value']) for value
                                  in record['ResourceRecords']]
            if content is not None and content not in record_content:
                continue
            LOGGER.debug('record: %s', record)
            records.append({
                'type': record['Type'],
                'name': self._full_name(record['Name']),
                'ttl': record.get('TTL', None),
                'content': record_content[0] if len(record_content) == 1 else record_content,
            })
        LOGGER.debug('list_records: %s', records)
        return records
447027
def query_dns(cls, domains, records):
        
        results = {k: set() for k in records}
        for record in records:
            for domain in domains:
                try:
                    answers = cls.resolver.query(domain, record)
                    for answer in answers:
                        # Add value to record type
                        results.get(record).add(answer)
                except (resolver.NoAnswer, resolver.NXDOMAIN, resolver.NoNameservers):
                    # Type of record doesn't fit domain or no answer from ns
                    continue

        return {k: v for k, v in results.items() if v}