使用nslookup
命令(在Windows上)或Linux上的host
命令,计算机可以在DNS中查询LDAP服务器(请参阅https://serverfault.com/questions/153526/how-can-i-find-the-ldap-server-in-the-dns-on-windows)。
是否可以使用Indy DNS解析程序组件执行这些查询?
nslookup -type=srv _ldap._tcp.DOMAINNAME
或
host -t srv _ldap._tcp.DOMAINNAME
答案 0 :(得分:6)
简单:
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.