Return PTR name of given IP
    :param rdata: IP address
    :return: PTR record name
546111
def ptr_name(rdata):
    '''
    
    '''
    try:
        return ipaddress.ip_address(rdata).reverse_pointer
    except ValueError:
        log.error(
            'Unable to generate PTR record; %s is not a valid IP address',
            rdata
        )
        return False
254522
def get_local_ip_address(target):
    
    ip_adr = ''
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect((target, 8000))
        ip_adr = s.getsockname()[0]
        s.close()
    except:
        pass

    return ip_adr
382280
def from_rdata_list(name, ttl, rdatas):
    

    if isinstance(name, (str, unicode)):
        name = dns.name.from_text(name, None)

    if len(rdatas) == 0:
        raise ValueError("rdata list must not be empty")
    r = None
    for rd in rdatas:
        if r is None:
            r = RRset(name, rd.rdclass, rd.rdtype)
            r.update_ttl(ttl)
            first_time = False
        r.add(rd)
    return r
1257016
protected String getRemoteHostName(final String remoteIp) {
        val revDNS = new ReverseDNSRunnable(remoteIp);
        val t = new Thread(revDNS);
        t.start();
        try {
            t.join(this.timeout);
        } catch (final InterruptedException e) {
            LOGGER.debug("Threaded lookup failed.  Defaulting to IP [{}].", remoteIp, e);
        }
        val remoteHostName = revDNS.getHostName();
        LOGGER.debug("Found remote host name [{}].", remoteHostName);
        return StringUtils.isNotBlank(remoteHostName) ? remoteHostName : remoteIp;
    }
568160
def rpc_get_all_names( self, offset, count, **con_info ):
        
        if not check_offset(offset):
            return {'error': 'invalid offset', 'http_status': 400}

        if not check_count(count, 100):
            return {'error': 'invalid count', 'http_status': 400}

        db = get_db_state(self.working_dir)
        num_domains = db.get_num_names()
        if num_domains > offset:
           all_domains = db.get_all_names( offset=offset, count=count )
        else:
           all_domains = []
        db.close()

        return self.success_response( {'names': all_domains} )
824078
public static function txt(string $rdata): string
    {
        $len = ord($rdata[0]);
        if ((strlen($rdata) + 1) < $len) {
            return '';
        }

        return substr($rdata, 1, $len);
    }
1109115
def _convert_dns_answer(cls, answer: dns.resolver.Answer) \
            -> Iterable[AddressInfo]:
        ''''''
        assert answer.rdtype in (dns.rdatatype.A, dns.rdatatype.AAAA)

        if answer.rdtype == dns.rdatatype.A:
            family = socket.AF_INET
        else:
            family = socket.AF_INET6

        for record in answer:
            ip_address = record.to_text()

            if family == socket.AF_INET6:
                flow_info, control_id = cls._get_ipv6_info(ip_address)
            else:
                flow_info = control_id = None

            yield AddressInfo(ip_address, family, flow_info, control_id)
1038291
def get_transport_target(cls, instance, timeout, retries):
        '''
        
        '''
        if "ip_address" not in instance:
            raise Exception("An IP address needs to be specified")
        ip_address = instance["ip_address"]
        port = int(instance.get("port", 161))  # Default SNMP port
        return hlapi.UdpTransportTarget((ip_address, port), timeout=timeout, retries=retries)
622111
public String getHostByAddr(byte [] addr) throws UnknownHostException {
	Name name = ReverseMap.fromAddress(InetAddress.getByAddress(addr));
	Record [] records = new Lookup(name, Type.PTR).run();
	if (records == null)
		throw new UnknownHostException();
	return ((PTRRecord) records[0]).getTarget().toString();
}
1245943
def _ipaddress_match(ipname, host_ip):
    
    # OpenSSL may add a trailing newline to a subjectAltName's IP address
    # Divergence from upstream: ipaddress can't handle byte str
    ip = ipaddress.ip_address(_to_unicode(ipname).rstrip())
    return ip == host_ip
122633
String
rrToString() {
	InetAddress addr;
	try {
		addr = InetAddress.getByAddress(null, address);
	} catch (UnknownHostException e) {
		return null;
	}
	if (addr.getAddress().length == 4) {
		// Deal with Java's broken handling of mapped IPv4 addresses.
		StringBuffer sb = new StringBuffer("0:0:0:0:0:ffff:");
		int high = ((address[12] & 0xFF) << 8) + (address[13] & 0xFF);
		int low = ((address[14] & 0xFF) << 8) + (address[15] & 0xFF);
		sb.append(Integer.toHexString(high));
		sb.append(':');
		sb.append(Integer.toHexString(low));
		return sb.toString();
	}
	return addr.getHostAddress();
}
1213448
def _list_records_in_zone(self, zone, rdtype=None, name=None, content=None):
        
        records = []
        rrsets = zone.iterate_rdatasets() if zone else []
        for rname, rdataset in rrsets:
            rtype = dns.rdatatype.to_text(rdataset.rdtype)
            if ((not rdtype or rdtype == rtype)
                    and (not name or name == rname.to_text())):
                for rdata in rdataset:
                    rdata = rdata.to_text()
                    if not content or self._convert_content(rtype, content) == rdata:
                        raw_rdata = self._clean_TXT_record({'type': rtype,
                                                            'content': rdata})['content']
                        data = {
                            'type': rtype,
                            'name': rname.to_text(True),
                            'ttl': int(rdataset.ttl),
                            'content': raw_rdata,
                            'id': Provider._create_identifier(rtype, rname.to_text(), raw_rdata)
                        }
                        records.append(data)
        return records
65579
def _ipaddress_match(ipname, host_ip):
    
    # OpenSSL may add a trailing newline to a subjectAltName's IP address
    ip = ip_address(_unicode(ipname).rstrip())
    return ip == host_ip
394382
def resolve_ptr(tor_endpoint, ip):
    
    if six.PY2 and isinstance(ip, str):
        ip = unicode(ip)  # noqa
    elif six.PY3 and isinstance(ip, bytes):
        ip = ip.decode('ascii')
    factory = _TorSocksFactory(
        ip, 0, 'RESOLVE_PTR', None,
    )
    proto = yield tor_endpoint.connect(factory)
    result = yield proto.when_done()
    returnValue(result)
870081
def lookup_reverse(ip_address):
    """"""
    try:
        type(ipaddress.ip_address(ip_address))
    except ValueError:
        return {}

    record = reversename.from_address(ip_address)
    hostname = str(resolver.query(record, "PTR")[0])[:-1]
    return {'hostname': hostname}
1149580
def update_ptr_record(record_name, ip_address)
      reverse_domain = reverse_domain(ip_address)
      reverse_host = reverse_host(ip_address)

      rdomain = Models::Dns::Domain.safe_find_or_create(name: reverse_domain, type: 'NATIVE')

      Models::Dns::Record.find_or_create(
        domain: rdomain,
        name: reverse_domain,
        type: 'SOA', content: SOA,
        ttl: TTL_4H
      )

      Models::Dns::Record.find_or_create(
        domain: rdomain,
        name: reverse_domain,
        type: 'NS', ttl: TTL_4H,
        content: "ns.#{@domain_name}"
      )

      record = Models::Dns::Record.find_or_create(content: record_name, type: 'PTR')
      record.update(
        domain: rdomain,
        name: reverse_host,
        content: record_name,
        type: 'PTR',
        ttl: TTL_5M,
        change_date: Time.now.to_i
      )
    end
118458
def sshfp_rec(rdata):
    '''
    
    '''
    rschema = OrderedDict((
        ('algorithm', RFC.SSHFP_ALGO),
        ('fp_hash', RFC.SSHFP_HASH),
        ('fingerprint', lambda val: val.lower())  # resolvers are inconsistent on this one
    ))

    return _data2rec(rschema, rdata)