Analysis of the IP address is the host domain name

zhaozj2021-02-11  245

Analyze the IP address as the host domain name.

Use WinSock unit; follows: 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: = gethStbyAddr (@ SockAddrin.sin_addr.s_addr, 4, af_Inet); if Hostent <> nil dam result: = strpas (hostent ^ .h_name) end else begin result: = '; end; end;

Please in the online state when testing.

Test code: var name: String; begin name: = inputbox ('Enter the other party host ip', 'host IP address:', ''); showMessage (iPaddrtoname (Name));

END;

转载请注明原文地址:https://www.9cbs.com/read-3849.html

New Post(0)