Skip to content

DnsServer & DnsClient

RockyLOMO edited this page Jun 25, 2021 · 7 revisions

` @SneakyThrows @Test public void dns() { final String domain = "devops.f-li.cn"; final InetAddress hostResult = InetAddress.getByName("2.2.2.2"); DnsServer server = new DnsServer(53); server.getCustomHosts().put(domain, hostResult.getAddress());

    System.out.println(Sockets.resolveAddresses("devops.f-li.cn"));
    System.out.println(Sockets.getAddresses("devops.f-li.cn"));

    sleep(2000);
    DnsClient client = new DnsClient(Sockets.parseEndpoint("127.0.0.1:53"));
    InetAddress result = client.resolve(domain);

    assert result.equals(hostResult);

    System.in.read();
}

`