1

I use the following code, results are correct. I am working on LAN with just 3 machines. Also that network is not connected to the internet. It takes 16 secs for only this line

HostEnt := gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);

GetHostByName(PChar(HostName)); is instant (delphitricks.com/source-code/internet/…)

function IPAddrToName(IPAddr: string): string;  
var   
  SockAddrIn: TSockAddrIn;   
  HostEnt: PHostEnt;   
  WSAData: TWSAData;   
begin   
  WSAStartup($101, WSAData);   
  SockAddrIn.sin_addr.s_addr := inet_addr(PChar(IPAddr));   
  HostEnt := gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);   
  if HostEnt <> nil then   
    Result := StrPas(Hostent^.h_name)   
  else   
    Result := '';   
end;   

https://stackoverflow.com/questions/3446879/gethostbyaddr-too-slow

Result of ipcofig /all (from machine running gethostbyaddr)

Windows IP Configuration

        Host Name . . . . . . . . . . . . : XXX
        Primary Dns Suffix  . . . . . . . : 
        Node Type . . . . . . . . . . . . : Unknown
        IP Routing Enabled. . . . . . . . : No
        WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  . : 
        Description . . . . . . . . . . . : Realtek RTL8139/810x Family Fast Ethernet NIC
        Physical Address. . . . . . . . . : 00-XX-XX-XX-xx-XX
        Dhcp Enabled. . . . . . . . . . . : No
        IP Address. . . . . . . . . . . . : 192.168.1.123
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.1.1
        DNS Servers . . . . . . . . . . . : 202.149.208.90
                                            202.149.208.11
1
  • Can you post the results of ipconfig /all? Commented Aug 10, 2010 at 13:39

1 Answer 1

0

It could be that you are having two dns servers, and first one is not working so your windows machine waits for timeout from first host (10+secs) and then tries second dns. Try changing dns to something else, like some public dns service and see if it makes a difference.

1
  • I tried on some other networks. It takes one or two seconds. Is there no method to obtain Name from IP in millisecs ? Commented Aug 13, 2010 at 3:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .