How to find an LDAP server in DNS using Indy?

Using the nslookup command (on Windows) or the host on Linux, the computer can query DNS for the LDAP server (see https://serverfault.com/questions/153526/how-can-i-find-the-ldap-server-in- the-dns-on-windows ).

Is it possible to fulfill these queries using the Indy DNS resolver component?

 nslookup -type=srv _ldap._tcp.DOMAINNAME 

or

 host -t srv _ldap._tcp.DOMAINNAME 
+4
source share
1 answer

Just:

 program SO18309621; {$APPTYPE CONSOLE} uses IdDNSResolver, SysUtils; var Dns : TIdDNSResolver; Rec : TResultRecord; Srv : TSRVRecord; Index : Integer; begin try Dns := TIdDNSResolver.Create; try Dns.Host := 'mydnsserver.mydomain'; Dns.QueryType := [qtService]; Dns.Resolve('_ldap._tcp.mydomain'); for Index := 0 to Dns.QueryResult.Count - 1 do begin Rec := Dns.QueryResult[Index]; if Rec is TSRVRecord then begin Srv := TSRVRecord(Rec); Writeln('Target=', Srv.Target, ', Port=', Srv.Port, ', Priority=', Srv.Priority, ', Weight=', Srv.Weight); end; end; finally Dns.Free; end; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. 
+6
source

Source: https://habr.com/ru/post/1497750/


All Articles