Search in sources :

Example 6 with Lookup

use of org.xbill.DNS.Lookup in project ORCID-Source by ORCID.

the class OrcidDomainValidator method isValid.

public boolean isValid(String hostLocation) {
    try {
        Lookup lookup = new Lookup(hostLocation);
        lookup.run();
        int result = lookup.getResult();
        if (Lookup.SUCCESSFUL == result) {
            return true;
        }
        if (Lookup.HOST_NOT_FOUND == result || Lookup.TYPE_NOT_FOUND == result) {
            return false;
        }
        LOGGER.warn("DNS is not OK, so validating in offline mode");
        return standardDomainValidator.isValid(hostLocation);
    } catch (TextParseException e) {
        return false;
    }
}
Also used : Lookup(org.xbill.DNS.Lookup) TextParseException(org.xbill.DNS.TextParseException)

Example 7 with Lookup

use of org.xbill.DNS.Lookup in project camel by apache.

the class DnsServiceDiscovery method getServices.

@Override
public List<ServiceDefinition> getServices(String name) {
    final Lookup lookup = cache.computeIfAbsent(name, this::createLookup);
    final Record[] records = lookup.run();
    List<ServiceDefinition> services;
    if (Objects.nonNull(records) && lookup.getResult() == Lookup.SUCCESSFUL) {
        services = Arrays.stream(records).filter(SRVRecord.class::isInstance).map(SRVRecord.class::cast).sorted(COMPARATOR).map(record -> asService(name, record)).collect(Collectors.toList());
    } else {
        services = Collections.emptyList();
    }
    return services;
}
Also used : Lookup(org.xbill.DNS.Lookup) SRVRecord(org.xbill.DNS.SRVRecord) Record(org.xbill.DNS.Record) SRVRecord(org.xbill.DNS.SRVRecord) DefaultServiceDefinition(org.apache.camel.impl.cloud.DefaultServiceDefinition) ServiceDefinition(org.apache.camel.cloud.ServiceDefinition)

Example 8 with Lookup

use of org.xbill.DNS.Lookup in project opennms by OpenNMS.

the class DnsMonitorIT method testDnsJavaQuadARecord.

@Test
public void testDnsJavaQuadARecord() throws IOException {
    assumeTrue(!Boolean.getBoolean("skipIpv6Tests"));
    final Lookup l = new Lookup("ipv6.example.com", Type.AAAA);
    // make sure we use a temporary cache so don't get results from a previously cached query
    // from another test
    l.setCache(null);
    final SimpleResolver resolver = new SimpleResolver("::1");
    resolver.setPort(9153);
    l.setResolver(resolver);
    l.run();
    System.out.println("result: " + l.getResult());
    if (l.getResult() == Lookup.SUCCESSFUL) {
        System.out.println(l.getAnswers()[0].rdataToString());
    }
    assertTrue(l.getResult() == Lookup.SUCCESSFUL);
}
Also used : Lookup(org.xbill.DNS.Lookup) SimpleResolver(org.xbill.DNS.SimpleResolver) Test(org.junit.Test)

Example 9 with Lookup

use of org.xbill.DNS.Lookup in project opennms by OpenNMS.

the class DnsMonitorIT method testNoAnswer.

@Test
@JUnitDNSServer(port = 9153, zones = {})
public void testNoAnswer() throws Exception {
    final Lookup l = new Lookup("example.com", Type.AAAA);
    // make sure we use a temporary cache so don't get results from a previously cached query
    // from another test
    l.setCache(null);
    final SimpleResolver resolver = new SimpleResolver("::1");
    resolver.setPort(9153);
    l.setResolver(resolver);
    l.run();
    // and NXRRSET record should be sent meaning that the server has no records for
    // example.com at all.  This results in a null answers.  This is result 4 I think
    System.out.println("result: " + l.getResult());
    final Record[] answers = l.getAnswers();
    assertNull(answers);
}
Also used : Lookup(org.xbill.DNS.Lookup) Record(org.xbill.DNS.Record) SimpleResolver(org.xbill.DNS.SimpleResolver) JUnitDNSServer(org.opennms.core.test.dns.annotations.JUnitDNSServer) Test(org.junit.Test)

Example 10 with Lookup

use of org.xbill.DNS.Lookup in project opennms by OpenNMS.

the class DnsUtilsTest method testOrderingOfLookups.

/**
 * Make sure this test is FIRST.
 */
@Test
@Ignore
public void testOrderingOfLookups() throws Exception {
    // String lookup = "www.opennms.org";
    String lookup = "www.facebook.com";
    Record[] fb = new Lookup(lookup, Type.AAAA).run();
    fb = new Lookup(lookup, Type.A).run();
    assertNotNull(fb);
}
Also used : Record(org.xbill.DNS.Record) Lookup(org.xbill.DNS.Lookup) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Lookup (org.xbill.DNS.Lookup)33 Record (org.xbill.DNS.Record)26 TextParseException (org.xbill.DNS.TextParseException)12 ArrayList (java.util.ArrayList)10 SRVRecord (org.xbill.DNS.SRVRecord)10 Name (org.xbill.DNS.Name)8 SimpleResolver (org.xbill.DNS.SimpleResolver)6 UnknownHostException (java.net.UnknownHostException)5 List (java.util.List)5 Test (org.junit.Test)5 ARecord (org.xbill.DNS.ARecord)5 InetAddress (java.net.InetAddress)4 ExtendedResolver (org.xbill.DNS.ExtendedResolver)4 SortedSet (java.util.SortedSet)3 PTRRecord (org.xbill.DNS.PTRRecord)3 HashSet (java.util.HashSet)2 Cache (org.xbill.DNS.Cache)2 NSRecord (org.xbill.DNS.NSRecord)2 NonNull (androidx.annotation.NonNull)1 Stream (com.annimon.stream.Stream)1