Search in sources :

Example 1 with DnsClient

use of org.minidns.DnsClient in project minidns by MiniDNS.

the class NSIDTest method testNsidLRoot.

@IntegrationTest
public static NSID testNsidLRoot() {
    DNSClient client = new DNSClient(null) {

        @Override
        protected Builder newQuestion(Builder message) {
            message.getEdnsBuilder().addEdnsOption(NSID.REQUEST);
            return super.newQuestion(message);
        }
    };
    DNSMessage response = null;
    Question q = new Question("de", TYPE.NS);
    for (InetAddress lRoot : IterativeDNSClient.getRootServer('l')) {
        try {
            response = client.query(q, lRoot);
        } catch (IOException e) {
            continue;
        }
        break;
    }
    NSID nsid = response.getEdns().getEdnsOption(OptionCode.NSID);
    assertNotNull(nsid);
    return nsid;
}
Also used : IterativeDNSClient(org.minidns.iterative.IterativeDNSClient) DNSClient(org.minidns.DNSClient) NSID(org.minidns.edns.NSID) Builder(org.minidns.dnsmessage.DNSMessage.Builder) Question(org.minidns.dnsmessage.Question) IOException(java.io.IOException) InetAddress(java.net.InetAddress) DNSMessage(org.minidns.dnsmessage.DNSMessage)

Example 2 with DnsClient

use of org.minidns.DnsClient in project minidns by MiniDNS.

the class AsyncApiTest method simpleAsyncApiTest.

public static void simpleAsyncApiTest() throws IOException {
    DNSClient client = new DNSClient();
    client.setDataSource(new AsyncNetworkDataSource());
    client.getDataSource().setTimeout(60 * 60 * 1000);
    MiniDnsFuture<DNSMessage, IOException> future = client.queryAsync("example.com", Record.TYPE.NS);
    DNSMessage response = future.getOrThrow();
    assertEquals(RESPONSE_CODE.NO_ERROR, response.responseCode);
}
Also used : DNSClient(org.minidns.DNSClient) IOException(java.io.IOException) AsyncNetworkDataSource(org.minidns.source.async.AsyncNetworkDataSource) DNSMessage(org.minidns.dnsmessage.DNSMessage)

Example 3 with DnsClient

use of org.minidns.DnsClient in project minidns by MiniDNS.

the class AsyncApiTest method tcpAsyncApiTest.

public static void tcpAsyncApiTest() throws IOException {
    DNSDataSource dataSource = new AsyncNetworkDataSource();
    dataSource.setTimeout(60 * 60 * 1000);
    dataSource.setUdpPayloadSize(256);
    dataSource.setQueryMode(QueryMode.tcp);
    DNSClient client = new DNSClient();
    client.setDataSource(dataSource);
    client.setAskForDnssec(true);
    MiniDnsFuture<DNSMessage, IOException> future = client.queryAsync("google.com", Record.TYPE.AAAA);
    DNSMessage response = future.getOrThrow();
    assertEquals(RESPONSE_CODE.NO_ERROR, response.responseCode);
}
Also used : DNSDataSource(org.minidns.source.DNSDataSource) DNSClient(org.minidns.DNSClient) IOException(java.io.IOException) AsyncNetworkDataSource(org.minidns.source.async.AsyncNetworkDataSource) DNSMessage(org.minidns.dnsmessage.DNSMessage)

Example 4 with DnsClient

use of org.minidns.DnsClient in project minidns by MiniDNS.

the class CoreTest method testExampleCom.

@IntegrationTest
public static void testExampleCom() throws IOException {
    DNSClient client = new DNSClient(new LRUCache(1024));
    // stable?
    String exampleIp4 = "93.184.216.34";
    // stable?
    String exampleIp6 = "2606:2800:220:1:248:1893:25c8:1946";
    assertEquals(client.query("example.com", Record.TYPE.A).answerSection.get(0).payloadData.toString(), exampleIp4);
    assertEquals(client.query("www.example.com", Record.TYPE.A).answerSection.get(0).payloadData.toString(), exampleIp4);
    assertEquals(client.query("example.com", Record.TYPE.AAAA).answerSection.get(0).payloadData.toString(), exampleIp6);
    assertEquals(client.query("www.example.com", Record.TYPE.AAAA).answerSection.get(0).payloadData.toString(), exampleIp6);
    DNSMessage nsRecords = client.query("example.com", Record.TYPE.NS);
    List<String> values = new ArrayList<>();
    for (Record<? extends Data> record : nsRecords.answerSection) {
        values.add(record.payloadData.toString());
    }
    Collections.sort(values);
    assertEquals(values.get(0), "a.iana-servers.net.");
    assertEquals(values.get(1), "b.iana-servers.net.");
}
Also used : DNSClient(org.minidns.DNSClient) LRUCache(org.minidns.cache.LRUCache) ArrayList(java.util.ArrayList) DNSMessage(org.minidns.dnsmessage.DNSMessage)

Example 5 with DnsClient

use of org.minidns.DnsClient in project minidns by MiniDNS.

the class CoreTest method testTcpAnswer.

@IntegrationTest
public static void testTcpAnswer() throws IOException {
    DNSClient client = new DNSClient(new LRUCache(1024));
    client.setAskForDnssec(true);
    client.setDisableResultFilter(true);
    DNSMessage result = client.query("www-nsec.example.com", Record.TYPE.A);
    assertNotNull(result);
    assertTrue(result.toArray().length > 512);
}
Also used : DNSClient(org.minidns.DNSClient) LRUCache(org.minidns.cache.LRUCache) DNSMessage(org.minidns.dnsmessage.DNSMessage)

Aggregations

DNSClient (org.minidns.DNSClient)5 DNSMessage (org.minidns.dnsmessage.DNSMessage)5 IOException (java.io.IOException)3 LRUCache (org.minidns.cache.LRUCache)2 Question (org.minidns.dnsmessage.Question)2 AsyncNetworkDataSource (org.minidns.source.async.AsyncNetworkDataSource)2 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 DnsClient (org.minidns.DnsClient)1 Builder (org.minidns.dnsmessage.DNSMessage.Builder)1 DnsMessage (org.minidns.dnsmessage.DnsMessage)1 DnssecClient (org.minidns.dnssec.DnssecClient)1 DnssecValidationFailedException (org.minidns.dnssec.DnssecValidationFailedException)1 NSID (org.minidns.edns.NSID)1 IterativeDNSClient (org.minidns.iterative.IterativeDNSClient)1 DNSDataSource (org.minidns.source.DNSDataSource)1