Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Redes (https://www.clubdelphi.com/foros/forumdisplay.php?f=37)
-   -   Ayuda,Al obtener una ip con winsock no es la ip correcta (https://www.clubdelphi.com/foros/showthread.php?t=77784)

neokobu 26-02-2012 02:49:41

Ayuda,Al obtener una ip con winsock no es la ip correcta
 
Al cambiar un codigo de delphi7 a delphi XE en ves de obtener la ip 192.168.1.6 me da como resultado 5.2.12.26. , el hostname si lo regresa correctamente.

Alguien tiene alguna idea?

Este es el codigo que tengo:
Cita:

procedure TfrmLogin.FormCreate(Sender: TObject);
var
wVersionRequested : WORD;
wsaData : TWSAData;
begin
{Start up WinSock}
wVersionRequested := MAKEWORD(1, 1);
WSAStartup(wVersionRequested, wsaData);
end;

procedure TfrmLogin.FormShow(Sender: TObject);
var
p : PHostEnt;
s : array[0..128] of char;
p2 : pAnsichar;
begin
{Get the computer name}
GetHostName(@s, 128);
p := GetHostByName(@s);
hostname1:=p^.h_Name;
{Get the IpAddress}
p2 :=iNet_ntoa(PInAddr(p^.h_addr_list^)^);
ipaddress:=p2;

end;


olbeup 27-02-2012 08:34:41

Hola neokobu,

Esta función que yo utilizo funciona correctamente
Código Delphi [-]
function GetIPComputer: String;
var
  wVersionRequested: Word;
  wsaData: TWSAData;
  pHostName: PHostEnt;
  sComputerName: Array[0..128] of Char;
  pIPComputer: PChar;
begin
  {Iniciar el WinSock}
  wVersionRequested := MakeWord(1, 1);
  WSAStartup(wVersionRequested, wsaData);

  {Obtener el nombre del ordenador}
  gethostname(@sComputerName, 128);
  pHostName := gethostbyname(@sComputerName);

  {Obtener la dirección IP}
  pIPComputer := inet_ntoa(PInAddr(pHostName^.h_addr_list^)^);
  Result := pIPComputer;

  {Cerrar el WinSock}
  WSACleanup;
end;
Un saludo.


La franja horaria es GMT +2. Ahora son las 16:32:43.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi