DNS query in JAVA

旧时模样 提交于 2019-12-04 04:49:41

You cannot lookup TXT or other DNS records InetAddress class. InetAddress.getAllByName() looks up for A, or AAAA records only.

Check DNS Java for your needs.

InetAddress doesn't do this, but you can accomplish DNS TXT record lookups in Java via the JNDI DNS provider.

Here is an example that does what you are trying to do:

Attribute attr = new InitialDirContext().getAttributes("dns:_netblocks.google.com", new String[] {"TXT"}).get("TXT");
System.out.println("attr.get() = " + attr.get());
System.out.println("attr.getAll() = " + Collections.list(attr.getAll()));

If you want to use a custom dns server use "dns://1.1/_netblocks.google.com" instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!