Pierre Pierre - 8 months ago 45
Java Question

Querying the DNS service records to find the hostname and TCP/IP

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 :

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.

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

How can I do this 'DNS' thing using the Java J2SE API (Without any external java library, I'd like a lightweight solution ) ?

Thank you


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" });

The returned attributes are an enumeration of strings that look like "1 0 80 ANIMALIA.ubio.org". The space separated fields are in order:

  1. priority
  2. weight
  3. port
  4. server