09-25-2023, 08:46 PM
(09-25-2023, 06:48 PM)BartKindt Wrote: I am getting lots of attemps to login to my server. I have the IP address, but would like to display in the Debug Log the reverse DNS name of the offending IP.
You can use GStack.HostByAddress() to ask the OS to get the host name of an IP, eg:
HostName := GStack.HostByAddress(AContext.Binding.PeerIP, AContext.Binding.IPVersion);
(09-25-2023, 06:48 PM)BartKindt Wrote: I just found the IdDNSResolver, but cannot seem to find an example of a reverse DNS looklup (IP4).
I don't have an exact example, but you should be able to configure TIdDNSResolver to use your desired DNS server, and then call its Resolve() method asking for the PTR record(s) for the target IP, eg:
Code:
IdDNSResolver.Host := ...;
IdDNSResolver.QueryType := [qtPTR];
IdDNSResolver.Resolve(PeerIP);
for I := 0 to IdDNSResolver.QueryResult.Count-1 do
begin
if IdDNSResolver.QueryResult[i].RecType = qtPTR then
begin
HostName := TPTRRecord(IdDNSResolver.QueryResult[i]).HostName;
// use HostName as needed...
end;
end;