查询DNS服务记录以查找主机名和TCP / IP [英] Querying the DNS service records to find the hostname and TCP/IP
问题描述
在有关生命科学标识符的论文中(见 LSID测试仪,用于测试生命科学标识符解析服务的工具),Dr.Roderic DM页面写道:
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,查询DNS的SRV记录为 _lsid._tcp 。 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.
我了解到,我可以使用主机链接_lsid._tcp.ubio.org到animalia.ubio.org:80, strong>命令在unix上:
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
我该怎么做这个DNS使用Java J2SE API的东西(没有任何外部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:
- 优先
- 重量
- port
- 服务器
- priority
- weight
- port
- server
这篇关于查询DNS服务记录以查找主机名和TCP / IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!