[jcifs] Re: jcifs.http.domainController

Eric Glass eric.glass at gmail.com
Thu Sep 8 13:16:42 GMT 2005


Just popping by...

>Actually, the FIRST thing you should do is write a very small simple test
>program like examples/ListDC.java to see that the _ldap._tcp.megacorp.com
>lookup actually works like the technet article claims.

I messed around with this at one point awhile back.  The SRV resource
records you want to look for are probably:

    _ldap._tcp.dc._msdcs.megacorp.com

i.e. the "dc._msdcs" entries; "_ldap._tcp.megacorp.com" is *any* LDAP
server, not necessarily a domain controller.  You can also look for
"_ldap._tcp.pdc._msdcs" to get the primary domain controller in a
mixed-mode domain (i.e. the box acting as the PDC for the NT-style
domain).  Similarly, you can look up "_kerberos._tcp" to find a
Kerberos KDC, or "_kerberos._tcp.dc._msdcs" for a Win2K domain
controller that is also a Kerberos KDC for the domain.

There are more details here:

http://www.microsoft.com/resources/documentation/Windows/2000/server/reskit/en-us/distrib/dsbc_nar_sdns.asp


See below for a small example.  It doesn't apply the
priorities/weights to the result list, that is an exercise left to the
reader ;)


import java.net.InetAddress;
import java.util.Enumeration;
import javax.naming.directory.*;

public class Lookup {

    public static void main(String[] args) throws Exception {
        String domain = args[0];
        DirContext context = new InitialDirContext();
        Attributes attributes = context.getAttributes(
                "dns:/_ldap._tcp.dc._msdcs." + domain,
                        new String[] { "SRV" });
        Enumeration values = attributes.get("SRV").getAll();
        while (values.hasMoreElements()) {
            String value = (String) values.nextElement();
            InetAddress server = InetAddress.getByName(value.replaceFirst(
                    "^\\d* \\d* \\d+ (.*)\\.$", "$1"));
            System.out.println(server);
        }
    }

}


More information about the jcifs mailing list