-
Notifications
You must be signed in to change notification settings - Fork 2
DnsServer & DnsClient
RockyLOMO edited this page Jul 15, 2021
·
7 revisions
@Test
public void dns() {
final String domain = "devops.f-li.cn";
final InetAddress hostResult = InetAddress.getByName("2.2.2.2");
DnsServer server = new DnsServer(54);
server.getCustomHosts().put(domain, hostResult.getAddress());
//注入变更 InetAddress.getAllByName 内部查询dnsServer的地址,支持非53端口
Sockets.injectNameService(Sockets.parseEndpoint("127.0.0.1:54"));
// System.out.println(HttpClient.godaddyDns("", "f-li.cn", "dd", "3.3.3.3"));
List<InetAddress> r0 = DnsClient.inlandClient().resolveAll(domain);
InetAddress[] r1 = InetAddress.getAllByName(domain);
System.out.println(r0 + "\n" + toJsonArray(r1));
assert !r0.get(0).equals(r1[0]);
sleep(2000);
DnsClient client = new DnsClient(Sockets.parseEndpoint("127.0.0.1:54"));
InetAddress result = client.resolve(domain);
assert result.equals(hostResult);
}