org.xbill.DNS.Resolver Java Examples

The following examples show how to use org.xbill.DNS.Resolver. 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: GoogleResolverCheck.java    From entrada with GNU General Public License v3.0 7 votes vote down vote up
@Override
protected List<String> fetch() {

  try {
    Resolver resolver = new SimpleResolver();
    // dns resolvers may take a long time to return a response.
    resolver.setTimeout(timeout);
    Lookup l =
        new Lookup(StringUtils.endsWith(hostname, ".") ? hostname : hostname + ".", Type.TXT);
    // always make sure the cache is empty
    l.setCache(new Cache());
    l.setResolver(resolver);
    Record[] records = l.run();
    if (records != null && records.length > 0) {
      return parse(records[0]);
    }
  } catch (Exception e) {
    log.error("Problem while adding Google resolvers, continue without", e);
  }

  log.error("No Google resolver addresses found");
  return Collections.emptyList();
}
 
Example #2
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 #3
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 #4
Source File: XBillDnsSrvResolverTest.java    From dns-java with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  lookupFactory = mock(LookupFactory.class);

  resolver = new XBillDnsSrvResolver(lookupFactory);

  xbillResolver = mock(Resolver.class);
}
 
Example #5
Source File: DNSJavaServiceTest.java    From james-project with Apache License 2.0 4 votes vote down vote up
public void setResolver(Resolver r) {
    resolver = r;
}
 
Example #6
Source File: SimpleLookupFactory.java    From dns-java with Apache License 2.0 4 votes vote down vote up
public SimpleLookupFactory(Resolver resolver) {
  this.resolver = resolver;
}
 
Example #7
Source File: Dig.java    From open-rmbt with Apache License 2.0 4 votes vote down vote up
public DnsRequest(Message resp, Message req, Resolver res, long duration) {
	this.response = resp;
	this.request = req;
	this.resolver = res;
	this.duration = duration;
}
 
Example #8
Source File: Dig.java    From open-rmbt with Apache License 2.0 4 votes vote down vote up
public Resolver getResolver() {
	return resolver;
}