Search in sources :

Example 6 with ExtendedResolver

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.");
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) Lookup(org.xbill.DNS.Lookup) Record(org.xbill.DNS.Record) Cache(org.xbill.DNS.Cache) Name(org.xbill.DNS.Name)

Example 7 with ExtendedResolver

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));
    }
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) SimpleResolver(org.xbill.DNS.SimpleResolver) ExtendedResolver(org.xbill.DNS.ExtendedResolver) Resolver(org.xbill.DNS.Resolver) UnknownHostException(java.net.UnknownHostException) SimpleResolver(org.xbill.DNS.SimpleResolver) Name(org.xbill.DNS.Name) TextParseException(org.xbill.DNS.TextParseException)

Example 8 with ExtendedResolver

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;
    }
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) UnknownHostException(java.net.UnknownHostException)

Example 9 with ExtendedResolver

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];
    }
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) ExtendedResolver(org.xbill.DNS.ExtendedResolver) Resolver(org.xbill.DNS.Resolver) Message(org.xbill.DNS.Message) Record(org.xbill.DNS.Record) Name(org.xbill.DNS.Name) Converter(org.apache.camel.Converter)

Example 10 with ExtendedResolver

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);
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) Lookup(org.xbill.DNS.Lookup) Record(org.xbill.DNS.Record) Name(org.xbill.DNS.Name)

Aggregations

ExtendedResolver (org.xbill.DNS.ExtendedResolver)16 UnknownHostException (java.net.UnknownHostException)8 Name (org.xbill.DNS.Name)6 Record (org.xbill.DNS.Record)6 Lookup (org.xbill.DNS.Lookup)5 X509Certificate (java.security.cert.X509Certificate)4 Resolver (org.xbill.DNS.Resolver)3 Certificate (java.security.cert.Certificate)2 Message (org.xbill.DNS.Message)2 SimpleResolver (org.xbill.DNS.SimpleResolver)2 TextParseException (org.xbill.DNS.TextParseException)2 File (java.io.File)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetAddress (java.net.InetAddress)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Converter (org.apache.camel.Converter)1 CacheException (org.apache.jcs.access.exception.CacheException)1 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)1