Ver Mensaje Individual
  #1  
Antiguo 30-06-2006
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.107
Reputación: 34
dec Tiene un aura espectaculardec Tiene un aura espectacular
En cliente, ¿cómo puedo obtener la dirección IP ó el Host?

(De las Faq's de Borland)

El ejemplo siguiente requiere el uso del API Winsock incorporado en el WinSock.pas.

Código Delphi [-]
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;
Responder Con Cita