Главная страница | назад





Article #15264: TCP/IP: Retrieving Client IP and Host Name

 Question and Answer Database
FAQ264D.txt — TCP/IP: Retrieving Client IP and Host Name
Category :DCOM/MultiTier/ActiveForm
Platform :All-32Bit
Product :
Question:
At client, how can I get the IP address or host name of
itself.
Answer:
The following example requires using the Winsock API
encapsulated in WinSock.pas.
uses
WinSock;
procedure GetHostInfo(var Name, Address: string);
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
{ no error checking...}
WSAStartup(2, WSAData);
SetLength(Name, 255);
Gethostname(PChar(Name), 255);
SetLength(Name, StrLen(PChar(Name)));
HostEnt := gethostbyname(PChar(Name));
with HostEnt^ do
Address := Format('%d.%d.%d.%d',[
Byte(h_addr^[0]),
Byte(h_addr^[1]),
Byte(h_addr^[2]),
Byte(h_addr^[3])]);
WSACleanup;
end;
4/2/99 11:39:52 AM

Last Modified: 01-SEP-99