InetAddress resolvedAddress = InetAddress.getByAddress(host, ipv4Record.getAddress().getAddress());
protected void storeDNSRecord(final CrawlURI curi, final String dnsName, final CrawlHost targetHost, final Record[] rrecordSet) { // Get TTL and IP info from the first A record (there may be // multiple, e.g. www.washington.edu) then update the CrawlServer ARecord arecord = getFirstARecord(rrecordSet); if (arecord == null) { throw new NullPointerException("Got null arecord for " + dnsName); } targetHost.setIP(arecord.getAddress(), arecord.getTTL()); try { recordDNS(curi, rrecordSet); curi.setFetchStatus(S_DNS_SUCCESS); curi.setDNSServerIPLabel(ResolverConfig.getCurrentConfig().server()); } catch (IOException e) { logger.log(Level.SEVERE, "Failed store of DNS Record for " + curi.toString(), e); setUnresolvable(curi, targetHost); } }
public List<InetAddress> resolve(String host) { List<InetAddress> hostIPs = new ArrayList<>(); try { Lookup lookup = new Lookup(host, Type.A); lookup.setResolver(resolver); Record[] records = lookup.run(); if (records == null) { return hostIPs; } for (Record record : records) { hostIPs.add(((ARecord) record).getAddress()); } } catch (TextParseException ex) { Log.e(TAG, ex.getMessage(), ex); throw new IllegalStateException(ex); } return hostIPs; }
/** * Finds A records (ip addresses) for the host name. * * @param name host name to resolve. * @return All the ip addresses found for the host name. * @throws UnknownHostException occurs when name is not available in DNS */ public InetAddress[] lookupAllHostAddr(String name) throws UnknownHostException { try { final Lookup lookup = new Lookup(name, Type.A); Record[] records = lookup.run(); if (records == null) { throw new UnknownHostException(name); } InetAddress[] array = new InetAddress[records.length]; for (int i = 0; i < records.length; i++) { ARecord a = (ARecord) records[i]; array[i] = a.getAddress(); } return array; } catch (TextParseException e) { throw new UnknownHostException(e.getMessage()); } }
private static InetAddress addrFromRecord(String name, Record r) throws UnknownHostException { ARecord a = (ARecord) r; return InetAddress.getByAddress(name, a.getAddress().getAddress()); }
private static InetAddress addrFromRecord(String name, Record r) throws UnknownHostException { ARecord a = (ARecord) r; return InetAddress.getByAddress(name, a.getAddress().getAddress()); }
private static InetAddress addrFromRecord(String name, Record r) throws UnknownHostException { ARecord a = (ARecord) r; return InetAddress.getByAddress(name, a.getAddress().getAddress()); }
@Nonnull protected static InetAddress toInetAddress(@Nonnull String name, @Nonnull ARecord record) { try { return InetAddress.getByAddress(name, record.getAddress().getAddress()); } catch (final UnknownHostException e) { throw new IllegalStateException("Could not convert " + record + " to address.", e); } }
private static InetAddress addrFromRecord(String name, Record r) throws UnknownHostException { InetAddress addr; if (r instanceof ARecord) { addr = ((ARecord)r).getAddress(); } else { addr = ((AAAARecord)r).getAddress(); } return InetAddress.getByAddress(name, addr.getAddress()); }
public static List<String> getIpFromHost(String hostname) throws TextParseException { List<String> result = new ArrayList<>(); Record[] recs = new Lookup(hostname, Type.A).run(); if (recs != null) { if (recs.length > 0) { for (Record rec : recs) { String ipAddress = ((ARecord) rec).getAddress().toString(); result.add(ipAddress.replace("/", "")); } } } return result; }
@Override public InetAddress getByName(String host) throws UnknownHostException { TimeMetric timeMetric = metricFactory.timer("getByName"); String name = allowIPLiteral(host); try { // Check if its local if (name.equalsIgnoreCase(localHostName) || name.equalsIgnoreCase(localCanonicalHostName) || name.equals(localAddress)) { return getLocalHost(); } return org.xbill.DNS.Address.getByAddress(name); } catch (UnknownHostException e) { Record[] records = lookupNoException(name, Type.A, "A"); if (records != null && records.length >= 1) { ARecord a = (ARecord) records[0]; return InetAddress.getByAddress(name, a.getAddress().getAddress()); } else { throw e; } } finally { timeMetric.stopAndPublish(); } }
public List<InetAddress> getAllAddresses(String hostName) throws UnknownHostException { Lookup lookup; try { lookup = new Lookup(hostName, Type.A); lookup.setCache(null); lookup.setResolver(new SimpleResolver(server)); } catch (TextParseException e) { throw new UnknownHostException(hostName); } List<InetAddress> addresses = new ArrayList<>(); Record[] a = lookup.run(); if (a == null || a.length == 0) { throw new UnknownHostException(hostName); } for (Record record : a) { addresses.add(((ARecord) record).getAddress()); } return addresses; } }
public static List<ForwardLookupResult> getARecord(String hostName, String domainName) throws TextParseException { List<ForwardLookupResult> entries = null; if (hostName != null && !hostName.isEmpty() && domainName != null && !domainName.isEmpty()) { Record[] recs = new Lookup(hostName, Type.A).run(); if (recs != null) { if (recs.length > 0) { entries = new ArrayList<>(); for (Record record : recs) { ForwardLookupResult foundSubDomain = new ForwardLookupResult(domainName); foundSubDomain.setHostName(hostName); String ipAddress = ((ARecord) record).getAddress().getHostAddress(); foundSubDomain.setIpAddress(ipAddress); foundSubDomain.setLookupType("A"); entries.add(foundSubDomain); } } } } return entries; }
@Override public InetAddress getByName(String host) throws UnknownHostException { TimeMetric timeMetric = metricFactory.timer("getByName"); String name = allowIPLiteral(host); try { // Check if its local if (name.equalsIgnoreCase(localHostName) || name.equalsIgnoreCase(localCanonicalHostName) || name.equals(localAddress)) { return getLocalHost(); } return org.xbill.DNS.Address.getByAddress(name); } catch (UnknownHostException e) { Record[] records = lookupNoException(name, Type.A, "A"); if (records != null && records.length >= 1) { ARecord a = (ARecord) records[0]; return InetAddress.getByAddress(name, a.getAddress().getAddress()); } else { throw e; } } finally { timeMetric.stopAndPublish(); } }
public List<ARecordResult> getARecord(String hostName) throws TextParseException { List<ARecordResult> entries = null; Record[] recs = new Lookup(hostName, Type.A).run(); if (recs != null) { if (recs.length > 0) { entries = new ArrayList<>(); for (Record record : recs) { ARecordResult foundSubDomain = new ARecordResult(NetworkTools.getDomainFromHost(hostName)); foundSubDomain.setHostName(hostName); String ipAddress = ((ARecord) record).getAddress().getHostAddress(); foundSubDomain.setIpAddress(ipAddress); foundSubDomain.setLookupType("A"); entries.add(foundSubDomain); } } } return entries; }
public static List<ARecordResult> getARecord(String hostName) throws TextParseException { List<ARecordResult> entries = null; Record[] recs = new Lookup(hostName, Type.A).run(); if (recs != null) { if (recs.length > 0) { entries = new ArrayList<>(); for (Record record : recs) { ARecordResult foundSubDomain = new ARecordResult(NetworkTools.getDomainFromHost(hostName)); foundSubDomain.setHostName(hostName); String ipAddress = ((ARecord) record).getAddress().getHostAddress(); foundSubDomain.setIpAddress(ipAddress); foundSubDomain.setLookupType("A"); entries.add(foundSubDomain); } } } return entries; }
protected void storeDNSRecord(final CrawlURI curi, final String dnsName, final CrawlHost targetHost, final Record[] rrecordSet) { // Get TTL and IP info from the first A record (there may be // multiple, e.g. www.washington.edu) then update the CrawlServer ARecord arecord = getFirstARecord(rrecordSet); if (arecord == null) { throw new NullPointerException("Got null arecord for " + dnsName); } targetHost.setIP(arecord.getAddress(), arecord.getTTL()); try { recordDNS(curi, rrecordSet); curi.setFetchStatus(S_DNS_SUCCESS); curi.setDNSServerIPLabel(ResolverConfig.getCurrentConfig().server()); } catch (IOException e) { logger.log(Level.SEVERE, "Failed store of DNS Record for " + curi.toString(), e); setUnresolvable(curi, targetHost); } }
protected List<DiscoveryNode> lookupNodes() throws TextParseException { List<DiscoveryNode> discoNodes = Lists.newArrayList(); for (Record srvRecord : lookupRecords(query, Type.SRV)) { logger.trace("Found SRV record {}", srvRecord); for (Record aRecord : lookupRecords(((SRVRecord) srvRecord).getTarget().toString(), Type.A)) { logger.trace("Found A record {} for SRV record", aRecord, srvRecord); String address = ((ARecord) aRecord).getAddress().getHostAddress() + ":" + ((SRVRecord) srvRecord).getPort(); try { for (TransportAddress transportAddress : transportService.addressesFromString(address)) { logger.trace("adding {}, transport_address {}", address, transportAddress); discoNodes.add(new DiscoveryNode("#srv-" + address + "-" + transportAddress, transportAddress, version.minimumCompatibilityVersion())); } } catch (Exception e) { logger.warn("failed to add {}, address {}", e, address); } } } return discoNodes; } }
@Test public void testContainerRegistration() 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("ctr-e50-1451931954322-0016-01-000002.dev.test."); assertEquals("wrong result", "172.17.0.19", ((ARecord) recs[0]).getAddress().getHostAddress()); recs = assertDNSQuery("httpd-1.test1.root.dev.test.", 1); assertTrue("not an ARecord", recs[0] instanceof ARecord); }
@Test public void testRecordTTL() 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( "ctr-e50-1451931954322-0016-01-000002.dev.test."); assertEquals("wrong result", "172.17.0.19", ((ARecord) recs[0]).getAddress().getHostAddress()); assertEquals("wrong ttl", 30L, recs[0].getTTL()); recs = assertDNSQuery("httpd-1.test1.root.dev.test.", 1); assertTrue("not an ARecord", recs[0] instanceof ARecord); assertEquals("wrong ttl", 30L, recs[0].getTTL()); }