Atozed Forums
Indy reverse DNS lookup IP4 - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Indy (https://www.atozed.com/forums/forum-8.html)
+--- Forum: Indy General Discussion (https://www.atozed.com/forums/forum-9.html)
+--- Thread: Indy reverse DNS lookup IP4 (/thread-3520.html)



Indy reverse DNS lookup IP4 - BartKindt - 09-25-2023

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.
I just found the IdDNSResolver, but cannot seem to find an example of a reverse DNS looklup (IP4).

Thanks


RE: Indy reverse DNS lookup IP4 - rlebeau - 09-25-2023

(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;



RE: Indy reverse DNS lookup IP4 - BartKindt - 09-30-2023

Thanks Remy, the "GStack.HostByAddress" was the solution for me.