@Override protected List<SRVRecord> lookupSRVRecords0(DnsName name, List<HostAddress> failedAddresses, DnssecMode dnssecMode) { List<SRVRecord> res = new ArrayList<>(); Lookup lookup; try { lookup = new Lookup(name.ace, Type.SRV); } catch (TextParseException e) { throw new IllegalStateException(e); } Record[] recs = lookup.run(); if (recs == null) return res; for (Record record : recs) { org.xbill.DNS.SRVRecord srvRecord = (org.xbill.DNS.SRVRecord) record; if (srvRecord != null && srvRecord.getTarget() != null) { DnsName host = DnsName.from(srvRecord.getTarget().toString()); int port = srvRecord.getPort(); int priority = srvRecord.getPriority(); int weight = srvRecord.getWeight(); List<InetAddress> hostAddresses = lookupHostAddress0(host, failedAddresses, dnssecMode); if (shouldContinue(name, host, hostAddresses)) { continue; } SRVRecord r = new SRVRecord(host, port, priority, weight, hostAddresses); res.add(r); } } return res; }
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; }
/** * @see org.apache.james.jdkim.api.PublicKeyRecordRetriever#getRecords(java.lang.CharSequence, java.lang.CharSequence, java.lang.CharSequence) */ public List<String> getRecords(CharSequence methodAndOptions, CharSequence selector, CharSequence token) throws TempFailException, PermFailException { if (!"dns/txt".equals(methodAndOptions)) throw new PermFailException("Only dns/txt is supported: " + methodAndOptions + " options unsupported."); try { Lookup query = new Lookup(selector + "._domainkey." + token, Type.TXT); query.setResolver(resolver); Record[] rr = query.run(); int queryResult = query.getResult(); if (queryResult == Lookup.TRY_AGAIN) { throw new TempFailException(query.getErrorString()); } List<String> records = convertRecordsToList(rr); return records; } catch (TextParseException e) { // TODO log return null; } }
private static boolean resolve(final Name name, final Resolver resolver, final int type) { final Lookup lookup = new Lookup(name, type); // NMS-9238: Do not use a cache when looking up the record, // that kind of defeats the purpose of this monitor :) lookup.setCache(null); lookup.setResolver(resolver); final Record[] records = lookup.run(); if (records == null) { return false; } return Arrays.stream(records) .filter(r -> r.getType() == type) .count() > 0; } }
Lookup l = new Lookup(namestr, type); l.setCache(cache); l.setResolver(resolver); l.setCredibility(dnsCredibility); l.setSearchPath(searchPaths); Record[] r = l.run(); if (l.getResult() == Lookup.TRY_AGAIN) { throw new TemporaryResolutionException("DNSService is temporary not reachable"); } else {
public List<Record> performSRVLookup(String replacement) { if(logger.isDebugEnabled()) { logger.debug("doing SRV lookup for replacement " + replacement); } Record[] srvRecords = null; try { Lookup lookup = new Lookup(replacement, Type.SRV); lookup.getDefaultResolver().setTimeout(dnsTimeout); lookup.getDefaultResolver().setTimeout(dnsTimeout, 0); srvRecords = lookup.run(); } catch (TextParseException e) { logger.error("Impossible to parse the parameters for dns lookup",e); } if(srvRecords != null && srvRecords.length > 0) { return Arrays.asList(srvRecords); } return new ArrayList<Record>(0); }
Lookup l = new Lookup(zname, Type.NS); Record [] ns = l.run(); if (ns == null) { System.out.println("failed to look up NS record: " + l.getErrorString()); System.exit(1);
private static Record [] lookupHostName(String name, boolean all) throws UnknownHostException { try { Lookup lookup = new Lookup(name, Type.A); Record [] a = lookup.run(); if (a == null) { if (lookup.getResult() == Lookup.TYPE_NOT_FOUND) { Record [] aaaa = new Lookup(name, Type.AAAA).run(); if (aaaa != null) return aaaa; } throw new UnknownHostException("unknown host"); } if (! all) return a; Record [] aaaa = new Lookup(name, Type.AAAA).run(); if (aaaa == null) return a; Record [] merged = new Record[a.length + aaaa.length]; System.arraycopy(a, 0, merged, 0, a.length); System.arraycopy(aaaa, 0, merged, a.length, aaaa.length); return merged; } catch (TextParseException e) { throw new UnknownHostException("invalid name"); } }
@Nonnull protected Lookup createLookupFor(@Nonnull String query, @Nonnegative int type) { final Lookup lookup; try { lookup = new Lookup(query, type); } catch (final TextParseException e) { throw new IllegalArgumentException("Could not parse query: " + query, e); } final Resolver resolver = _resolver; lookup.setResolver(resolver != null ? resolver : getDefaultResolver()); lookup.setCache(null); return lookup; }
@Override public List<LookupResult> resolve(final String fqdn) { Lookup lookup = lookupFactory.forName(fqdn); Record[] queryResult = lookup.run(); switch (lookup.getResult()) { case Lookup.SUCCESSFUL: return toLookupResults(queryResult); case Lookup.HOST_NOT_FOUND: // fallthrough case Lookup.TYPE_NOT_FOUND: LOG.warn("No results returned for query '{}'; result from XBill: {} - {}", fqdn, lookup.getResult(), lookup.getErrorString()); return ImmutableList.of(); default: throw new DnsException( String.format("Lookup of '%s' failed with code: %d - %s ", fqdn, lookup.getResult(), lookup.getErrorString())); } }
@Nonnull protected Lookup createLookup (@Nonnull final String sHost) throws TextParseException { final Lookup aDNSLookup = new Lookup (sHost, Type.ANY); try { aDNSLookup.setResolver (new SimpleResolver ()); } catch (final UnknownHostException ex) { // Shit happens - no special resolver needed } // No cache! aDNSLookup.setCache (null); return aDNSLookup; }
@Override public Record[] run() { return lu.run(); }
@Override public Lookup forName(String fqdn) { try { final Lookup lookup = new Lookup(fqdn, Type.SRV, DClass.IN); if (resolver != null) { lookup.setResolver(resolver); } return lookup; } catch (TextParseException e) { throw new DnsException("unable to create lookup for name: " + fqdn, e); } } }
@Before public void setUp() throws Exception { dnsServer = new TestableDNSServer(); DefaultConfigurationBuilder db = new DefaultConfigurationBuilder(); db.load(new ByteArrayInputStream(DNS_SERVER_CONFIG)); dnsServer.configure(db); dnsServer.init(); defaultCache = Lookup.getDefaultCache(DClass.IN); defaultResolver = Lookup.getDefaultResolver(); defaultSearchPaths = Lookup.getDefaultSearchPath(); Lookup.setDefaultCache(null, DClass.IN); Lookup.setDefaultResolver(null); Lookup.setDefaultSearchPath(new Name[]{}); dnsServer.setResolver(null); mockedCache = mock(Cache.class); }
public LookupAdapter(Name name, int type){ lu = new org.xbill.DNS.Lookup(name, type); }
this.dclass = dclass; synchronized (Lookup.class) { this.resolver = getDefaultResolver(); this.searchPath = getDefaultSearchPath(); this.cache = getDefaultCache(dclass);
public static void printAnswer(String name, Lookup lookup) { System.out.print(name + ":"); int result = lookup.getResult(); if (result != Lookup.SUCCESSFUL) System.out.print(" " + lookup.getErrorString()); System.out.println(); Name [] aliases = lookup.getAliases(); if (aliases.length > 0) { System.out.print("# aliases: "); for (int i = 0; i < aliases.length; i++) { System.out.print(aliases[i]); if (i < aliases.length - 1) System.out.print(" "); } System.out.println(); } if (lookup.getResult() == Lookup.SUCCESSFUL) { Record [] answers = lookup.getAnswers(); for (int i = 0; i < answers.length; i++) System.out.println(answers[i]); } }
/** * Default Constructor. * Uses the DNSJava static DefaultResolver */ public DNSServiceXBillImpl(Logger logger) { this(logger, Lookup.getDefaultResolver()); }
protected void checkResult(@Nonnull String query, @Nonnull Lookup lookup) throws NoSuchSrvRecordException, UnknownHostException, SocketException { final int result = lookup.getResult(); if (result == HOST_NOT_FOUND) { throw new NoSuchSrvRecordException("Could not find srv entry for query '" + query + "' on remote " + toStringOfResolver(lookup) + "."); } else if (result == TYPE_NOT_FOUND) { throw new UnknownHostException("Could not find the host that should contain the srv entry for query '" + query + "' on remote " + toStringOfResolver(lookup) + "."); } else if (result == TRY_AGAIN) { throw new ServiceTemporaryUnavailableException("Could not get information from remote " + toStringOfResolver(lookup) + "."); } else if (result != 0) { throw new RuntimeException("Could not get information from remote " + toStringOfResolver(lookup) + ". Got: " + lookup.getErrorString()); } }