检查Java中名称服务器的dns查找 [英] Check the dns lookup of a nameserver in Java

查看:250
本文介绍了检查Java中名称服务器的dns查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于域和名称服务器ip,我想知道在java中解析IP的名称服务器在哪里,我该如何实现它?谢谢

Given a domain and a nameserver ip I'd like to know where is that nameserver resolving the IP in java, how can I achieve it? Thanks

推荐答案

您至少有两个选择:

如果你的代码必须在任何VM上运行,您必须使用许多可用的Java DNS库之一。谷歌搜索java dns库将为您提供许多选项。

If your code has to run on any VM, you must use one of the many available Java DNS libraries. Googling for "java dns library" will give you many options.

如果您的代码只能在Sun / Oracle VM上运行,您可以使用专有的JNDI DNS像这样的提供者:

If your code is only going to run on a Sun/Oracle VM, you can use the proprietary JNDI DNS provider like this:

Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
env.put("java.naming.provider.url",    "dns://<your DNS server>");

DirContext ictx = new InitialDirContext(env);
Attributes attrs = ictx.getAttributes("www.heise.de", new String[] {"A", "AAAA"});

NamingEnumeration<? extends Attribute> e = attrs.getAll();
while(e.hasMoreElements()) {
    Attribute a = e.next();
    System.out.println(a.getID() + " = " + a.get());
}

此示例将在指定的DNS服务器中查询所有A和AAAA记录主持人www.heise.de:

This example will query the specified DNS server for all A and AAAA records for the host www.heise.de:

A = 193.99.144.85

A = 193.99.144.85

AAAA = 2a02:2e0:3fe: 100 :: 7

AAAA = 2a02:2e0:3fe:100::7

这篇关于检查Java中名称服务器的dns查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆