Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Indy reverse DNS lookup IP4
#1
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
---
Bart Kindt
CEO and Developer
SARTrack Limited
New Zealand
www.sartrack.nz
Reply
#2
(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;

Reply
#3
Thanks Remy, the "GStack.HostByAddress" was the solution for me.
---
Bart Kindt
CEO and Developer
SARTrack Limited
New Zealand
www.sartrack.nz
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)