// DNS = TIdDNSResolver
s := '
www.delphipraxis.net';
// oder eine IP
DNS.Host := Reg.NameServer;
// Dein DNS-Server
DNS.ClearInternalQuery;
DNS.QueryType := [qtA];
// Liefert einen A- und einen Name-Record - hier auch mal die anderen möglichen Varianten probieren z. B. qtName
Reg.WriteAppInfoLog(Format('
DNS-Abfrage: Host = %s',[s]));
Try
DNS.Resolve(s);
Reg.WriteAppInfoLog('
DomainName: %s',[DNS.QueryResult.DomainName]);
if DNS.QueryResult.Count > 0
then begin
for i := 0
to DNS.QueryResult.Count - 1
do begin
case DNS.QueryResult.Items[I].RecType
of
qtA:
begin
if Trim(TARecord(DNS.QueryResult.Items[I]).IPAddress) = '
'
then begin
Reg.WriteAppInfoLog('
IP: %s', [GetIPFromRData(DNS.QueryResult.Items[I].RData)]);
end else begin
Reg.WriteAppInfoLog('
IP: %s',[TARecord(DNS.QueryResult.Items[I]).IPAddress]);
end;
end;
qtNS: Reg.WriteAppLog('
' + TNSRecord(DNS.QueryResult.Items[I]).HostName);
qtMD: Reg.WriteAppLog('
' + TResultRecord(DNS.QueryResult.Items[I]).
Name);
qtMF: Reg.WriteAppLog('
' + TResultRecord(DNS.QueryResult.Items[I]).
Name);
qtName: Reg.WriteAppLog('
' + TNAMERecord(DNS.QueryResult.Items[I]).HostName);
qtSOA:
begin
Reg.WriteAppLog('
Primary: ' + TSOARecord(DNS.QueryResult.Items[I]).Primary);
Reg.WriteAppLog('
ResponsiblePerson: ' + TSOARecord(DNS.QueryResult.Items[I]).ResponsiblePerson);
Reg.WriteAppLog('
Serial: ' + IntToStr(TSOARecord(DNS.QueryResult.Items[I]).Serial));
Reg.WriteAppLog('
Refresh: ' + IntToStr(TSOARecord(DNS.QueryResult.Items[I]).Refresh));
Reg.WriteAppLog('
Retry: ' + IntToStr(TSOARecord(DNS.QueryResult.Items[I]).Retry));
Reg.WriteAppLog('
Expire: ' + IntToStr(TSOARecord(DNS.QueryResult.Items[I]).Expire));
Reg.WriteAppLog('
MinimumTTL: ' + IntToStr(TSOARecord(DNS.QueryResult.Items[I]).MinimumTTL));
end;
qtMB: Reg.WriteAppLog('
' + TResultRecord(DNS.QueryResult.Items[I]).
Name);
qtMG: Reg.WriteAppLog('
' + TResultRecord(DNS.QueryResult.Items[I]).
Name);
qtMR: Reg.WriteAppLog('
' + TResultRecord(DNS.QueryResult.Items[I]).
Name);
qtWKS:
begin
Reg.WriteAppLog('
' + TWKSRecord(DNS.QueryResult.Items[I]).IPAddress);
Reg.WriteAppLog('
' + IntToStr(TWKSRecord(DNS.QueryResult.Items[I]).Protocol));
end;
qtPTR: Reg.WriteAppLog('
' + TPTRRecord(DNS.QueryResult.Items[I]).HostName);
qtHINFO:
begin
Reg.WriteAppLog('
' + THINFORecord(DNS.QueryResult.Items[I]).CPU);
Reg.WriteAppLog('
' + THINFORecord(DNS.QueryResult.Items[I]).OS);
end;
qtMINFO:
begin
Reg.WriteAppLog('
' + TMINFORecord(DNS.QueryResult.Items[I]).ResponsiblePersonMailbox);
Reg.WriteAppLog('
' + TMINFORecord(DNS.QueryResult.Items[I]).ErrorMailbox);
end;
qtMX: Reg.WriteAppLog('
' + TMXRecord(DNS.QueryResult.Items[I]).ExchangeServer+'
,' + IntToStr(TMXRecord(DNS.QueryResult.Items[I]).Preference));
qtTXT: Reg.WriteAppLog(TTextRecord(DNS.QueryResult.Items[I]).Text.Text);
else
Reg.WriteAppLog('
?:');
Reg.WriteAppLog('
' + TResultRecord(DNS.QueryResult.Items[I]).
Name);
Reg.WriteAppLog('
' + TResultRecord(DNS.QueryResult.Items[I]).RData);
end;
end;
end else begin
Reg.WriteAppErrorLog('
Kein Ergebnis erhalten.');
end;
DNS.Disconnect;
except
on e :
Exception do begin
Reg.WriteAppInfoLog('
DNS-Abfrage: ' + e.
Message);
try
DNS.Disconnect;
except
end;
end;
end;
...
function GetIPFromRData(RData : TIDBytes) :
String;
var
s :
String;
i : Integer;
begin
s := BytesToString(RData);
if Length(s) = 4
then begin
Result := '
';
for i := 1
to Length(s)
do Result := Result + IntToStr(Ord(s[i])) + '
.';
Result := Copy(Result,1,Length(Result) - 1);
end else begin
Result := s;
end;
end;