org.xbill.DNS.ExtendedResolver Java Examples

The following examples show how to use org.xbill.DNS.ExtendedResolver. 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: CustomDns.java    From KinoCast with MIT License 6 votes vote down vote up
private void init() {
    if (mInitialized) return; else mInitialized = true;

    try {
        // configure the resolvers, starting with the default ones (based on the current network connection)
        Resolver defaultResolver = Lookup.getDefaultResolver();
        // use Google's public DNS services
        Resolver googleFirstResolver = new SimpleResolver("8.8.8.8");
        Resolver googleSecondResolver = new SimpleResolver("8.8.4.4");
        // also try using Amazon
        Resolver amazonResolver = new SimpleResolver("205.251.198.30");
        Lookup.setDefaultResolver(new ExtendedResolver(new Resolver[]{
                googleFirstResolver, googleSecondResolver, amazonResolver, defaultResolver }));
    } catch (UnknownHostException e) {
        Log.w(TAG, "Couldn't initialize custom resolvers");
    }
}
 
Example #2
Source File: DnsSrvResolvers.java    From dns-java with Apache License 2.0 5 votes vote down vote up
public DnsSrvResolver build() {
  Resolver resolver;
  try {
    // If the user specified DNS servers, create a new ExtendedResolver which uses them.
    // Otherwise, use the default constructor. That will use the servers in ResolverConfig,
    // or if that's empty, localhost.
    resolver = servers == null ?
               new ExtendedResolver() :
               new ExtendedResolver(servers.toArray(new String[servers.size()]));
  } catch (UnknownHostException e) {
    throw new RuntimeException(e);
  }

  // Configure the Resolver to use our timeouts.
  final Duration timeoutDuration = Duration.ofMillis(dnsLookupTimeoutMillis);
  resolver.setTimeout(timeoutDuration);

  LookupFactory lookupFactory = new SimpleLookupFactory(resolver);

  if (cacheLookups) {
    lookupFactory = new CachingLookupFactory(lookupFactory);
  }

  DnsSrvResolver result = new XBillDnsSrvResolver(lookupFactory);

  if (reporter != null) {
    result = new MeteredDnsSrvResolver(result, reporter);
  }

  if (retainData) {
    result = new RetainingDnsSrvResolver(result, retentionDurationMillis);
  }

  return result;
}
 
Example #3
Source File: DNSLookupService.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void init(final ServiceFactory factory) throws UnknownHostException {
	_resolver = new ExtendedResolver();
}
 
Example #4
Source File: DNSJavaService.java    From james-project with Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void init() throws Exception {
    LOGGER.debug("DNSService init...");

    // If no DNS servers were configured, default to local host
    if (dnsServers.isEmpty()) {
        try {
            dnsServers.add(InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException ue) {
            dnsServers.add("127.0.0.1");
        }
    }

    // Create the extended resolver...
    final String[] serversArray = dnsServers.toArray(String[]::new);

    if (LOGGER.isInfoEnabled()) {
        for (String aServersArray : serversArray) {
            LOGGER.info("DNS Server is: " + aServersArray);
        }
    }

    try {
        resolver = new ExtendedResolver(serversArray);
    } catch (UnknownHostException uhe) {
        LOGGER.error("DNS service could not be initialized.  The DNS servers specified are not recognized hosts.", uhe);
        throw uhe;
    }

    cache = new Cache(DClass.IN);
    cache.setMaxEntries(maxCacheSize);
    cache.setMaxNCache(negativeCacheTTL);

    if (setAsDNSJavaDefault) {
        Lookup.setDefaultResolver(resolver);
        Lookup.setDefaultCache(cache, DClass.IN);
        Lookup.setDefaultSearchPath(searchPaths);
        LOGGER.info("Registered cache, resolver and search paths as DNSJava defaults");
    }

    // Cache the local hostname and local address. This is needed because
    // the following issues:
    // JAMES-787
    // JAMES-302
    InetAddress addr = getLocalHost();
    localCanonicalHostName = addr.getCanonicalHostName();
    localHostName = addr.getHostName();
    localAddress = addr.getHostAddress();

    LOGGER.debug("DNSService ...init end");
}