我正在尝试使用Linux shell和Java查询特定的DNS服务器。
使用dig命令可以正常工作,但Java方法则不行。这是怎么回事? dig @dns.nic.it test.it
;; QUESTION SECTION: ;test.it. IN A
;; AUTHORITY SECTION: test.it. 10800 IN NS dns2.technorail.com. test.it. 10800 IN NS dns.technorail.com. test.it. 10800 IN NS dns3.arubadns.net. test.it. 10800 IN NS dns4.arubadns.cz.
Java方法:
public static void rootDNSLookup(String domainName) throws NamingException{
String server="dns://dns.nic.it";
Hashtable env = new Hashtable(); env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); env.put("java.naming.provider.url", server);
DirContext ictx = new InitialDirContext(env); Attributes attrs = ictx.getAttributes(domainName, new String[] {"A", "AAAA", "NS", "SRV"}); System.out.println(attrs); NamingEnumeration e = attrs.getAll(); while(e.hasMoreElements()) { Attribute a = e.next(); System.out.println(a.getID() + " = " + a.get()); }
}
Java输出:
没有属性