use of org.xbill.DNS.ExtendedResolver in project nhin-d by DirectProject.
the class DNSConnectionTest method performLookup.
private static void performLookup() throws Exception {
// turn on debug settings for the DNS client
Options.set("verbose", "true");
Cache ch = Lookup.getDefaultCache(DClass.IN);
ch.clearCache();
if (servers == null || servers.length == 0)
servers = ResolverConfig.getCurrentConfig().servers();
System.out.println("\r\nConfigure DNS resolvers:");
for (String server : servers) {
System.out.println("\t" + server);
}
System.out.println("\r\nLookup up record " + lookupRec);
Lookup lu = new Lookup(new Name(lookupRec), recType);
ExtendedResolver resolver = new ExtendedResolver(servers);
resolver.setTCP(useTCP);
lu.setResolver(resolver);
Record[] retRecords = lu.run();
if (retRecords != null && retRecords.length > 0)
System.out.println(retRecords.length + " records found.");
else
System.out.println("No records found.");
}
use of org.xbill.DNS.ExtendedResolver in project opennms by OpenNMS.
the class DNSResolutionMonitor method poll.
@Override
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
// Get the name to query for
final Name name;
try {
name = new Name(svc.getNodeLabel());
} catch (final TextParseException e) {
return PollStatus.unavailable("Invalid record name '" + svc.getNodeLabel() + "': " + e.getMessage());
}
// Determine if records for IPv4 and/or IPv6 re required
final String resolutionType = ParameterMap.getKeyedString(parameters, PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_DEFAULT);
final boolean ipv4Required = PARM_RESOLUTION_TYPE_V4.equalsIgnoreCase(resolutionType) || PARM_RESOLUTION_TYPE_BOTH.equals(resolutionType);
final boolean ipv6Required = PARM_RESOLUTION_TYPE_V6.equalsIgnoreCase(resolutionType) || PARM_RESOLUTION_TYPE_BOTH.equals(resolutionType);
// Build a resolver object used for lookups
final String nameserver = ParameterMap.getKeyedString(parameters, PARM_NAMESERVER, null);
final Resolver resolver;
try {
if (nameserver == null) {
// Use system-defined resolvers
resolver = new ExtendedResolver();
} else {
resolver = new SimpleResolver(nameserver);
}
} catch (final UnknownHostException e) {
return PollStatus.unavailable("Unable to resolve nameserver '" + nameserver + "': " + e.getMessage());
}
// Start resolving the records
final long start = System.currentTimeMillis();
// Resolve the name
final boolean ipv4Found = resolve(name, resolver, Type.A);
final boolean ipv6Found = resolve(name, resolver, Type.AAAA);
// Resolving succeeded - checking results
final long end = System.currentTimeMillis();
// Check if result is valid
if (!ipv4Found && !ipv6Found) {
return PollStatus.unavailable("Unable to resolve host '" + name + "'");
} else if (ipv4Required && !ipv4Found) {
return PollStatus.unavailable("'" + name + "' could be resolved to an IPv6 address (AAAA record) but not an IPv4 address (A record)");
} else if (ipv6Required && !ipv6Found) {
return PollStatus.unavailable("'" + name + "' could be resolved to an IPv4 address (A record) but not an IPv6 address (AAAA record)");
} else {
return PollStatus.available((double) (end - start));
}
}
use of org.xbill.DNS.ExtendedResolver in project jmeter by apache.
the class DNSCacheManager method createResolver.
/**
* @return {@link Resolver}
*/
private Resolver createResolver() {
CollectionProperty dnsServers = getServers();
try {
String[] serverNames = new String[dnsServers.size()];
int index = 0;
for (JMeterProperty jMeterProperty : dnsServers) {
serverNames[index] = jMeterProperty.getStringValue();
index++;
}
ExtendedResolver result = new ExtendedResolver(serverNames);
if (log.isDebugEnabled()) {
log.debug("Using DNS Resolvers: {}", Arrays.asList((result).getResolvers()));
}
// resolvers will be chosen via round-robin
result.setLoadBalance(true);
return result;
} catch (UnknownHostException uhe) {
this.initFailed = true;
log.warn("Failed to create Extended resolver: {}", uhe.getMessage(), uhe);
return null;
}
}
use of org.xbill.DNS.ExtendedResolver in project camel by apache.
the class DnsRecordConverter method toRecord.
/**
* @param ip, like "192.168.1.1"
* @return the complete DNS record for that IP.
*/
@Converter
public static Record toRecord(String ip) throws IOException {
Resolver res = new ExtendedResolver();
Name name = ReverseMap.fromAddress(ip);
int type = Type.PTR;
int dclass = DClass.IN;
Record rec = Record.newRecord(name, type, dclass);
Message query = Message.newQuery(rec);
Message response = res.send(query);
Record[] answers = response.getSectionArray(Section.ANSWER);
if (answers.length == 0) {
return null;
} else {
return answers[0];
}
}
use of org.xbill.DNS.ExtendedResolver in project nhin-d by DirectProject.
the class DNSConnectionTest method testDNSSocketConnectionUDPWithProxyStore.
public void testDNSSocketConnectionUDPWithProxyStore() throws Exception {
DNSServerSettings settings = new DNSServerSettings();
settings.setPort(AvailablePortFinder.getNextAvailable(1024));
DNSServer server = new DNSServer(new ProxyDNSStore(), settings);
server.start();
// give the server a couple seconds to start
Thread.sleep(2000);
// turn on debug settings for the DNS client
Options.set("verbose", "true");
Lookup lu = new Lookup(new Name("google.com"), Type.A);
ExtendedResolver resolver = new ExtendedResolver(IPUtils.getDNSLocalIps());
resolver.setTCP(false);
resolver.setPort(settings.getPort());
// default retries is 3, limite to 2
lu.setResolver(resolver);
Record[] retRecords = lu.run();
assertNotNull(retRecords);
server.stop();
Thread.sleep(2000);
}
Aggregations