0

Is there a way in Java to do a Nslookup search on SRV records?

I need to bind to Active Directory and would like to use the SRV records to help determine which of the ADs in the cluster are live.

In command line the nslookup search string is: 'nslookup -type=srv _ ldap._tcp.ActiveDirectory domain name'

Thanks.

4

3 回答 3

2

正如埃里克森所指出的,JNDI API 有一个使用 JNDI 的 DNS 提供程序,您可以在该链接上阅读它。_ldap._.tcp.mydomain.com有关查询记录的工作示例,请参阅来自 Hudson 的此代码

我相信在使用 DNS 提供商之前,您需要使用以下内容加载它(根据上面的 Hudson 代码修改):

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
env.put("java.naming.provider.url", "dns:");
DirContext ctx = new InitialDirContext(env);

从那里,您可以通过以下方式获取 SRV 记录:

Attributes attributes = ctx.getAttributes("_ldap._tcp.mydomain.com", new String[]{"SRV"});
Attribute a = attributes.get("SRV");

我已经成功地在几个项目中使用这样的代码来实现非常直接的 AD 集成。

于 2010-04-22T23:46:06.257 回答
0

我从未使用过它,但我相信 Java 的命名服务“JNDI”API有一个 DNS 提供者。将域名查找为DirContext,然后检查其“SRV”属性。

DirContext ctx = new InitialDirContext();
Attributes attrs = ctx.getAttributes("dns:/y.com", new String[] {"SRV"});

就像我说的,我没有尝试过这个,但我希望它可以帮助你开始。

于 2010-04-22T23:12:00.643 回答
0

我使用了http://www.dnsjava.org/它完成了这项工作

于 2012-01-21T21:52:41.357 回答