Atozed Forums

Full Version: Indy reverse DNS lookup IP4
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
(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;
Thanks Remy, the "GStack.HostByAddress" was the solution for me.