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?
Asked
Active
Viewed 565 times
2
-
Look into https://docs.ldap.com/ldap-sdk/docs/advantages/ease-of-use.html – JCompetence Nov 13 '20 at 11:52
-
Hi Susan, Thanks for providing reference link. – karthik raja Nov 16 '20 at 03:53
-
The question in we will be provided with only domain name and port details(example.com and 389). env.put(Context.PROVIDER_URL, "ldap://server.example.com:389/"); We have to identify the nearby server based on the domain name, so that we can pass it as ldap://server.example.com:389/ to create connection. – karthik raja Nov 16 '20 at 14:17
2 Answers
0
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

karthik raja
- 21
- 2
-
As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 19 '22 at 08:57
0
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

jla
- 6,904
- 2
- 36
- 34