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

后端 未结 4 1349
无人及你
无人及你 2021-01-02 18:47

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 :

相关标签:
4条回答
  • 2021-01-02 19:27

    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
    0 讨论(0)
  • 2021-01-02 19:33

    You can't do this using the standard Java libraries. The InetAddress class is only capable of looking up DNS A records.

    To look up SRV records (and indeed any other DNS resource record type other than an A record) you need a third party library. dnsjava is the usual option.

    I've personally used the 1.6 version on Google Android, it works fine. Version 2.0 and later use the Java nio layer, so won't be compatible with earlier JVMs.

    0 讨论(0)
  • 2021-01-02 19:34

    I think you can't do it without using some external libraries. java.util.InetAddress has some methods to resolve names via DNS, but it's only usable for resolving names into IP addresses and not for generic DNS querying.

    For that, you need some external library like DNSJava.

    0 讨论(0)
  • 2021-01-02 19:51

    In case anybody is looking for non-Java solutions (which they might given that the title of the question isn't language specific), when I implemented a LSID (see doi:10.1186/1751-0473-3-2) I used the PEAR package Net_DNS, which can look up SRV records.

    0 讨论(0)
提交回复
热议问题