查询 DNS 服务记录以查找主机名和 TCP/IP [英] Querying the DNS service records to find the hostname and TCP/IP
问题描述
在一篇关于生命科学标识符的论文中(参见LSID 测试器,一种用于测试生命科学标识符解析服务的工具),Roderic DM Page 博士写道:
In a paper about the Life Science Identifiers (see LSID Tester, a tool for testing Life Science Identifier resolution services), Dr Roderic DM Page wrote :
给定 LSID urn:lsid**:ubio.org**:namebank:11815,查询 _lsid._tcp 的 SRV 记录的 DNS.ubio.org 返回animalia.ubio.org:80 作为ubio.org LSID 服务的位置.
Given the LSID urn:lsid**:ubio.org**:namebank:11815, querying the DNS for the SRV record for _lsid._tcp.ubio.org returns animalia.ubio.org:80 as the location of the ubio.org LSID service.
我了解到我可以在 unix 上使用 host 命令将 _lsid._tcp.ubio.org 链接到animalia.ubio.org:80:
I learned that I can link _lsid._tcp.ubio.org to animalia.ubio.org:80 using the host command on unix:
host -t srv _lsid._tcp.ubio.org
_lsid._tcp.ubio.org has SRV record 1 0 80 ANIMALIA.ubio.org
我如何使用 Java J2SE API 来做这个DNS"事情(没有任何外部 Java 库,我想要一个轻量级的解决方案)?
How can I do this 'DNS' thing using the Java J2SE API (Without any external java library, I'd like a lightweight solution ) ?
谢谢
推荐答案
JNDI DNS 提供程序可以查找 SRV 记录.您需要执行以下操作:
The JNDI DNS provider can lookup SRV records. You need to do something like:
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
env.put("java.naming.provider.url", "dns:");
DirContext ctx = new InitialDirContext(env);
Attributes attrs = ctx.getAttributes("_lsid._tcp.ubio.org", new String[] { "SRV" });
返回的属性是字符串的枚举,看起来像1 0 80 ANIMALIA.ubio.org".空格分隔的字段按顺序排列:
The returned attributes are an enumeration of strings that look like "1 0 80 ANIMALIA.ubio.org". The space separated fields are in order:
- 优先事项
- 重量
- 端口
- 服务器
这篇关于查询 DNS 服务记录以查找主机名和 TCP/IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!