/** * Finds PTR records (reverse dns lookups) for the ip address. * * @param ip ip address to lookup. * @return The host name found for the ip address. * @throws UnknownHostException occurs when id is not available in DNS */ public String getHostByAddr(byte[] ip) throws UnknownHostException { try { String addr = DnsUtils.numericToTextFormat(ip); Record[] records = new Lookup(addr, Type.PTR).run(); if (records == null) { throw new UnknownHostException(addr); } PTRRecord ptr = (PTRRecord) records[0]; return ptr.getTarget().toString(); } catch (TextParseException e) { throw new UnknownHostException(e.getMessage()); } } }
/** * 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, IOException { Name name = ReverseMap.fromAddress(InetAddress.getByAddress(addr)); Record[] records = Lookup.lookupRecords(name, Type.PTR); if (records == null || records.length == 0) { throw new UnknownHostException(); } return ((PTRRecord) records[0]).getTarget().toString(); } }
/** * 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(); } }
/** * 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(); } }
/** * 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(); } }
/** * Determines the hostname for an address * @param addr The address to look up * @return The associated host name * @exception UnknownHostException There is no hostname for the address */ public static String getHostName(InetAddress addr) throws UnknownHostException { Name name = ReverseMap.fromAddress(addr); Record [] records = new Lookup(name, Type.PTR).run(); if (records == null) throw new UnknownHostException("unknown address"); PTRRecord ptr = (PTRRecord) records[0]; return ptr.getTarget().toString(); }
/** * Determines the hostname for an address * @param addr The address to look up * @return The associated host name * @exception UnknownHostException There is no hostname for the address */ public static String getHostName(InetAddress addr) throws UnknownHostException { Name name = ReverseMap.fromAddress(addr); Record [] records = new Lookup(name, Type.PTR).run(); if (records == null) throw new UnknownHostException("unknown address"); PTRRecord ptr = (PTRRecord) records[0]; return ptr.getTarget().toString(); }
/** * Determines the hostname for an address * @param addr The address to look up * @return The associated host name * @exception UnknownHostException There is no hostname for the address */ public static String getHostName(InetAddress addr) throws UnknownHostException { Name name = ReverseMap.fromAddress(addr); Record [] records = new Lookup(name, Type.PTR).run(); if (records == null) throw new UnknownHostException("unknown address"); PTRRecord ptr = (PTRRecord) records[0]; return ptr.getTarget().toString(); }
/** * Determines the hostname for an address * @param addr The address to look up * @return The associated host name * @exception UnknownHostException There is no hostname for the address */ public static String getHostName(InetAddress addr) throws UnknownHostException { Name name = ReverseMap.fromAddress(addr); Record [] records = new Lookup(name, Type.PTR).run(); if (records == null) throw new UnknownHostException("unknown address"); PTRRecord ptr = (PTRRecord) records[0]; return ptr.getTarget().toString(); }
case Type.PTR: PTRRecord ptr = (PTRRecord) rr[i]; records.add(IPAddr.stripDot(ptr.getTarget().toString())); break; case Type.TXT:
case Type.PTR: PTRRecord ptr = (PTRRecord) rr[i]; records.add(IPAddr.stripDot(ptr.getTarget().toString())); break; case Type.TXT:
/** * Performs a reverse DNS lookup. * * @param addr The ip address to lookup. * @return The host name found for the ip address. * Absent if the ip is not mapped, or something. * @throws IOException on a possibly temporary network error. */ private Optional<String> getHostByAddr(byte[] addr) throws IOException { Name name = ReverseMap.fromAddress(InetAddress.getByAddress(addr)); Record[] records; Lookup lookup; if (dnsServers!=null) { final Resolver res = new ExtendedResolver(dnsServers); lookup = new Lookup(name, Type.PTR); lookup.setResolver(res); records = lookup.run(); } else { lookup = new Lookup(name, Type.PTR); records = lookup.run(); } int result = lookup.getResult(); if (result==Lookup.TRY_AGAIN) { throw new IOException("Network error when trying to look up "+ Arrays.toString(addr) +", try again."); } if (result != Lookup.SUCCESSFUL || records == null) { return Optional.absent(); } return Optional.of(((PTRRecord) records[0]).getTarget().toString()); }
@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(); } }
@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(); } }
public void receiveRecord(final Object id, final Record record) { if (record.getTTL() > 0) { if (record.getType() == Type.PTR) { String value = ((PTRRecord) record).getTarget().toString(); if (!value.endsWith(".")) { value += "."; } // Check if domain is already in the list, add if not, otherwise manipulate booleans. try { domains.add(new Domain(new Name(value))); } catch (TextParseException e) { e.printStackTrace(System.err); } } } } });
if (shortSRVName.equals(((PTRRecord)record).getTarget()))
case Type.PTR: PTRRecord ptr = (PTRRecord) record; service = (ServiceInstance) services.get(ptr.getTarget()); if (service != null)
@Test public void testReverseLookup() throws Exception { ServiceRecord record = getMarshal().fromBytes("somepath", CONTAINER_RECORD.getBytes()); getRegistryDNS().register( "/registry/users/root/services/org-apache-slider/test1/components/" + "ctr-e50-1451931954322-0016-01-000002", record); // start assessing whether correct records are available Record[] recs = assertDNSQuery("19.0.17.172.in-addr.arpa.", Type.PTR, 1); assertEquals("wrong result", "httpd-1.test1.root.dev.test.", ((PTRRecord) recs[0]).getTarget().toString()); }
@Test public void testReverseLookupInLargeNetwork() throws Exception { setRegistryDNS(new RegistryDNS("TestRegistry")); Configuration conf = createConfiguration(); conf.set(RegistryConstants.KEY_DNS_DOMAIN, "dev.test"); conf.set(KEY_DNS_ZONE_SUBNET, "172.17.0.0"); conf.set(KEY_DNS_ZONE_MASK, "255.255.224.0"); conf.setTimeDuration(RegistryConstants.KEY_DNS_TTL, 30L, TimeUnit.SECONDS); getRegistryDNS().setDomainName(conf); getRegistryDNS().initializeZones(conf); ServiceRecord record = getMarshal().fromBytes("somepath", CONTAINER_RECORD.getBytes()); getRegistryDNS().register( "/registry/users/root/services/org-apache-slider/test1/components/" + "ctr-e50-1451931954322-0016-01-000002", record); // start assessing whether correct records are available Record[] recs = assertDNSQuery("19.0.17.172.in-addr.arpa.", Type.PTR, 1); assertEquals("wrong result", "httpd-1.test1.root.dev.test.", ((PTRRecord) recs[0]).getTarget().toString()); }