org.xbill.DNS.PTRRecord Java Examples

The following examples show how to use org.xbill.DNS.PTRRecord. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DNSJavaService.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Override
public String getHostName(InetAddress addr) {
    TimeMetric timeMetric = metricFactory.timer("getHostName");
    String result;
    Name name = ReverseMap.fromAddress(addr);
    Record[] records = lookupNoException(name.toString(), Type.PTR, "PTR");

    try {
        if (records == null) {
            result = addr.getHostAddress();
        } else {
            PTRRecord ptr = (PTRRecord) records[0];
            result = ptr.getTarget().toString();
        }
        return result;
    } finally {
        timeMetric.stopAndPublish();
    }
}
 
Example #2
Source File: Helperfunctions.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
public static String reverseDNSLookup(final InetAddress adr)
{
    try
    {
        final Name name = ReverseMap.fromAddress(adr);
        
        final Lookup lookup = new Lookup(name, Type.PTR);
        lookup.setResolver(new SimpleResolver());
        lookup.setCache(null);
        final Record[] records = lookup.run();
        if (lookup.getResult() == Lookup.SUCCESSFUL)
            for (final Record record : records)
                if (record instanceof PTRRecord)
                {
                    final PTRRecord ptr = (PTRRecord) record;
                    return ptr.getTarget().toString();
                }
    }
    catch (final Exception e)
    {
    }
    return null;
}
 
Example #3
Source File: DNSJavaNameService.java    From Virtual-Hosts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Performs a reverse DNS lookup.
 * @param addr The ip address to lookup.
 * @return The host name found for the ip address.
 */
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();
}
 
Example #4
Source File: DNSJavaNameService.java    From AndroidPNClient with Apache License 2.0 5 votes vote down vote up
/**
 * Performs a reverse DNS lookup.
 * @param addr The ip address to lookup.
 * @return The host name found for the ip address.
 */
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();
}
 
Example #5
Source File: DNSJavaNameService.java    From dnsjava with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Performs a reverse DNS lookup.
 *
 * @param addr The ip address to lookup.
 * @return The host name found for the ip address.
 */
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("Unknown address: " + name);
  }
  return ((PTRRecord) records[0]).getTarget().toString();
}
 
Example #6
Source File: IpAddressUtil.java    From megatron-java with Apache License 2.0 5 votes vote down vote up
private static String reverseDnsLookupUsingDnsJavaExtendedResolver(long ipAddress) throws UnknownHostException {
    byte[] address = convertLongAddressToBuf(ipAddress);
    Name name = ReverseMap.fromAddress(InetAddress.getByAddress(address));
    Record[] records = new Lookup(name, Type.PTR).run();
    if (records == null) {
        throw new UnknownHostException();
    }
    String result = ((PTRRecord)records[0]).getTarget().toString();
    // remove trailing "."
    result = result.endsWith(".") ? result.substring(0, result.length() - 1) : result;
    return result;
}
 
Example #7
Source File: DNS.java    From yeti with MIT License 4 votes vote down vote up
public static PTRRecord getPTRRecord(String ipAddress) {
    return null;
}
 
Example #8
Source File: DataAPI.java    From yeti with MIT License 4 votes vote down vote up
public PTRRecord getPTRRecord(String ipAddress) {
    return null;
}