Locate closest domain controller using Java

Viewed 325

I have to connect Active Directory and fetch data based on the domain names. Using LDAP connection with Java. For this I wanted to identify closest domain controller first. Is there any method or API available in Java to identify closest domain controller based on domain name?

2 Answers

To locate the domain controllers we can use LDAP queries(with site name) in java code.

Ex : srv _ldap._tcp.sitename._sites.example.net.local

According to Microsoft's How domain controllers are located in Windows, you can look up the LDAP SRV records of either of these forms:

  • _ldap._tcp.domainname
  • _ldap._tcp.dc._msdcs.domainname - this is karthik's sitename._sites example.

E.g. nslookup -type=srv _ldap._tcp.company.int if your computer's FQDN is name.company.int.

At least where I'm testing, it doesn't seem to give them with a weight or priority to indicate the closest. I found a similar question on ServerFault, Finding closest Domain Controller through LDAP, that dives further into figuring out the closest.

See also 6.3.2.3 SRV Records

Related