Board index » delphi » I have DNS, how about Reverse DNS?

I have DNS, how about Reverse DNS?

I use the following code to convert www.elitegamer.com to it's IP...
I'm trying to figure out how to do the opposite. Pass an IP, and reverse dns
it.

any help is appreciated.

-Matt

function getHostIp(HostName: String; var IP, ErrorMsg: String): Boolean;
var
  WSAData: TWSAData;
  oHost: PHostEnt;
  lnLoop: Integer;
begin
  RESULT:= FALSE;
  ErrorMsg:= '';
  IP:= '';
  if WSAStartup($0101, WSAData) <> 0 then
    begin
      ErrorMsg:= 'Winsock not responding.';
      Exit;
    end;

  oHost:= GetHostByName(PCHAR(HostName));
  if oHost <> nil then
    begin
      for lnLoop:= 0 to oHost.h_length - 1 do
        IP:= concat(IP, IntToStr(ORD(oHost.h_addr_list^[lnLoop])) + '.');
      SetLength(IP, Length(Ip) - 1);
      IP:= oHost.h_name;
      RESULT:= TRUE;
    end;
end;

 

Re:I have DNS, how about Reverse DNS?


"Matt Elzer" <dragon...@hotmail.com> wrote in news:3c6f2b72$1_2
@dnews:

Use GetHostByAddr

Re:I have DNS, how about Reverse DNS?


Actually, I tried that, and I get nothing but errors... I assume I'm doing
something horribly wrong. Do you have a clip of code you could paste?

-: Matt

Quote
"Hadi Hariri" <m...@hadihariri.com> wrote in message

news:Xns91B89FE37F62Fmailhadihariricom@207.105.83.65...
Quote
> "Matt Elzer" <dragon...@hotmail.com> wrote in news:3c6f2b72$1_2
> @dnews:

> Use GetHostByAddr

Re:I have DNS, how about Reverse DNS?


"Matt Elzer" <dragon...@hotmail.com> wrote in news:3c6ff679$1_2
@dnews:

Quote
> Actually, I tried that, and I get nothing but errors... I assume
I'm
> doing something horribly wrong. Do you have a clip of code you
could
> paste?

function TIdStackWindows.WSGetHostByAddr(const AAddress: string):
string;
var
  Host: PHostEnt;
  LAddr: Longint;
begin
  LAddr := inet_addr(PChar(AAddress));
  Host := GetHostByAddr(@LAddr, SizeOf(LAddr), AF_INET);
  if Host = nil then begin
    CheckForSocketError(SOCKET_ERROR);
  end else begin
    result := Host^.h_name;
  end;
end;

This is a code extract from Indy (IdStackWindows.pas)

Re:I have DNS, how about Reverse DNS?


Hadi, thanks a lot... I'm not sure what I was doing wrong, but this fixed
it.

I'm getting ready to start using INDY in my project (and move away from the
Delphi TClientSocket component), however I haven't started yet. Anyhow,
thanks again!

Matt

Quote
"Hadi Hariri" <m...@hadihariri.com> wrote in message

news:Xns91BA7CE3CABAmailhadihariricom@207.105.83.65...
Quote
> "Matt Elzer" <dragon...@hotmail.com> wrote in news:3c6ff679$1_2
> @dnews:

> > Actually, I tried that, and I get nothing but errors... I assume
> I'm
> > doing something horribly wrong. Do you have a clip of code you
> could
> > paste?
> function TIdStackWindows.WSGetHostByAddr(const AAddress: string):
> string;
> var
>   Host: PHostEnt;
>   LAddr: Longint;
> begin
>   LAddr := inet_addr(PChar(AAddress));
>   Host := GetHostByAddr(@LAddr, SizeOf(LAddr), AF_INET);
>   if Host = nil then begin
>     CheckForSocketError(SOCKET_ERROR);
>   end else begin
>     result := Host^.h_name;
>   end;
> end;

> This is a code extract from Indy (IdStackWindows.pas)

Other Threads