Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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;   

http://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
share|improve this question
    
Can you post the results of ipconfig /all? –  Tom Wijsman Aug 10 '10 at 13:39
add comment

1 Answer 1

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.

share|improve this answer
    
I tried on some other networks. It takes one or two seconds. Is there no method to obtain Name from IP in millisecs ? –  Allan Fernandes Aug 13 '10 at 3:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.