4

使用nslookup命令(在 Windows 上)或hostLinux 上的命令,计算机可以查询 LDAP 服务器的 DNS(请参阅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
4

1 回答 1

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.
于 2013-08-19T09:09:20.283 回答