Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 31-10-2017
rdaniel2000 rdaniel2000 is offline
Miembro
 
Registrado: jun 2003
Posts: 11
Poder: 0
rdaniel2000 Va por buen camino
Obtener el IP en Windows Server 2016

Hola,

Hay una funcion como esta para obtener el IP:

function ObtenerIp :string; //Es el truco 82 de trucomania (editado)
var
wVersionRequested : WORD;
wsaData : TWSAData;
p : PHostEnt;
s : array[0..128] of char;
begin
wVersionRequested := MAKEWORD(1, 1);
WSAStartup(wVersionRequested, wsaData);
GetHostName(@s, 128);
p := GetHostByName(@s);
Result := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
WSACleanUP;
end;

En todos los Windows funciona bien, pero ya en Windows Server 2016 Ya no funciona se genera un excepcion de error.

Alguien ya lo soluciono???
Responder Con Cita
  #2  
Antiguo 31-10-2017
[maeyanes] maeyanes is offline
Capo de los Capos
 
Registrado: may 2003
Ubicación: Campeche, México
Posts: 2.732
Poder: 23
maeyanes Va por buen camino
Hola...

¿Podrías especificar cual es el error que te muestra? Por que así como preguntas, pues como que no das mucha información.


Saludos...
__________________
Lee la Guía de Estilo antes que cualquier cosa. - Twitter
Responder Con Cita
  #3  
Antiguo 31-10-2017
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.011
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Cita:
Empezado por rdaniel2000 Ver Mensaje
Hola
No olvides poner los tags al código fuente, ejemplo:



Gracias
Responder Con Cita
  #4  
Antiguo 03-11-2017
Avatar de duilioisola
[duilioisola] duilioisola is online now
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.730
Poder: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Yo utilizo esa funcion en Windows 2016 Server y funciona correctamente.
Deberás decirnos qué excepción genera para tí. (Mensaje completo y sin traducir)
Responder Con Cita
  #5  
Antiguo 03-11-2017
rdaniel2000 rdaniel2000 is offline
Miembro
 
Registrado: jun 2003
Posts: 11
Poder: 0
rdaniel2000 Va por buen camino
Cita:
Empezado por duilioisola Ver Mensaje
Yo utilizo esa funcion en Windows 2016 Server y funciona correctamente.
Deberás decirnos qué excepción genera para tí. (Mensaje completo y sin traducir)
Creo que va a ser problema del Windows que tengo... que Build tienes del Windows Server 2016???

La version que tengo es:

Version 1607 (Compilacion de SO 14393.0) (En español)
Responder Con Cita
  #6  
Antiguo 03-11-2017
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.011
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Cita:
Empezado por rdaniel2000 Ver Mensaje
Creo que va a ser problema del Windows que tengo... que Build tienes del Windows Server 2016???
La version que tengo es:
Version 1607 (Compilacion de SO 14393.0) (En español)
Eso no tiene nada que ver, contesta la pregunta que te han hecho
Responder Con Cita
  #7  
Antiguo 03-11-2017
rdaniel2000 rdaniel2000 is offline
Miembro
 
Registrado: jun 2003
Posts: 11
Poder: 0
rdaniel2000 Va por buen camino
Cita:
Empezado por maeyanes Ver Mensaje
Hola...

¿Podrías especificar cual es el error que te muestra? Por que así como preguntas, pues como que no das mucha información.


Saludos...


Este es el Error que me marca, usando Delphi 7 / Sobre Windows Server 2016 Version 1607 (Compilacion de SO 14393.0)

Access violation at address 004764C1 in module 'Project1.exe'. Read of address 0000000C


CODIGO:

Código Delphi [-]


function ObtenerIp :string; //Es el truco 82 de trucomania (editado)
var
wVersionRequested : WORD;
wsaData : TWSAData;
p : PHostEnt;
s : array[0..128] of char;
begin
try
wVersionRequested := MAKEWORD(1, 1);
WSAStartup(wVersionRequested, wsaData);
GetHostName(@s, 128);
p := GetHostByName(@s);
Result := iNet_ntoa(PInAddr(p^.h_addr_list^)^);    // Aqui es donde se genera la Excepcion
WSACleanUP;
except
 on E: Exception do
   ShowMessage(E.Message);
end;
end;
Responder Con Cita
  #8  
Antiguo 03-11-2017
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.011
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Veo que es de aquí.

Yo uso lo mismo con una pequeña variación y funciona perfectamente:
Código Delphi [-]
function getIPnumber: string;
const
  _MAXSIZE_ = 48;
var
  buffer:Array [0.._MAXSIZE_+1] of char;
  PuntHost: PHostEnt;
  wVersionRequested: WORD;
  wsaData: TWSAData;
begin
  Result := '';
  wVersionRequested := MAKEWORD( 1, 1 );
  WSAStartup( wVersionRequested, wsaData );
  GetHostName( @buffer, _MAXSIZE_ );
  PuntHost := GetHostByName( @buffer );
  Result := iNet_ntoa( PInAddr( PuntHost^.h_addr_list^ )^ );
  WSACleanup;
end;
Responder Con Cita
  #9  
Antiguo 03-11-2017
rdaniel2000 rdaniel2000 is offline
Miembro
 
Registrado: jun 2003
Posts: 11
Poder: 0
rdaniel2000 Va por buen camino
Cita:
Empezado por Casimiro Notevi Ver Mensaje
.
Yo uso lo mismo con una pequeña variación y funciona perfectamente:
Código Delphi [-]
function getIPnumber: string;
const
  _MAXSIZE_ = 48;
var
  buffer:Array [0.._MAXSIZE_+1] of char;
  PuntHost: PHostEnt;
  wVersionRequested: WORD;
  wsaData: TWSAData;
begin
  Result := '';
  wVersionRequested := MAKEWORD( 1, 1 );
  WSAStartup( wVersionRequested, wsaData );
  GetHostName( @buffer, _MAXSIZE_ );
  PuntHost := GetHostByName( @buffer );
  Result := iNet_ntoa( PInAddr( PuntHost^.h_addr_list^ )^ );
  WSACleanup;
end;
Ya use tu codigo y me vuelve a marcar el mismo error de Excepcion...

Por ese motivo, yo creo que debe ser un problema en el Build del Windows Server... ya que cuando lo ejecuto en Windows 7, 10 o 2012 Server funciona muy bien...
Responder Con Cita
  #10  
Antiguo 03-11-2017
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.011
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
A ver si alguien lo prueba con la misma versión que tienes tú.
Responder Con Cita
  #11  
Antiguo 06-11-2017
Avatar de duilioisola
[duilioisola] duilioisola is online now
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.730
Poder: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Prueba con esta versión:
Notarás que hay una variable mas "P2" de tipo PChar.
Quizas la asignación directa del resultado de inet_ntoa que es PChar a String no le gusta.

Código Delphi [-]
function DameIPLocal: string;
var
  p : PHostEnt;
  s : array[0..128] of char;
  p2 : PChar;
  wVersionRequested : word;
  wsaData : TWSAData;
begin
  // Arranca la librería WinSock
  try
     wVersionRequested := MAKEWORD(1, 1);
     WSAStartup(wVersionRequested, wsaData);

     // Obtiene el nombre del PC
     GetHostName(@s, 128);
     p := GetHostByName(@s);

     // Obtiene la dirección IP y libera la librería WinSock
     p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
     Result := Result + p2;
     WSACleanup;
  except
     Result := '';
  end;
end;

Estuve leyendo que inet_ntoa devuelve null si ha encontrado un error.
Cita:
De la ayuda de Delphi 6:
The Windows Sockets inet_ntoa function converts a network address into a string in dotted format.

char FAR * inet_ntoa (
struct in_addr in
);


Parameters
[in] A structure which represents an Internet host address.

Remarks
This function takes an Internet address structure specified by the in parameter. It returns an ASCII string representing the address in ".'' notation as "a.b.c.d''. Note that the string returned by inet_ntoa resides in memory which is allocated by Windows Sockets. The application should not make any assumptions about the way in which the memory is allocated. The data is guaranteed to be valid until the next Windows Sockets function call within the same thread, but no longer.

Return Values
If no error occurs, inet_ntoa returns a char pointer to a static buffer containing the text address in standard ".'' notation. Otherwise, it returns NULL. The data should be copied before another Windows Sockets call is made.
Código Delphi [-]
function DameIPLocal: string;
var
  p : PHostEnt;
  s : array[0..128] of char;
  p2 : PChar;
  wVersionRequested : word;
  wsaData : TWSAData;
begin
  // Arranca la librería WinSock
  try
     wVersionRequested := MAKEWORD(1, 1);
     WSAStartup(wVersionRequested, wsaData);

     // Obtiene el nombre del PC
     GetHostName(@s, 128);
     p := GetHostByName(@s);

     // Obtiene la dirección IP y libera la librería WinSock
     p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
     if (Assigned(p2)) then
        Result := Result + p2
     else
        Result := '';
     WSACleanup;
  except
     Result := '';
  end;
end;
Responder Con Cita
  #12  
Antiguo 06-11-2017
rdaniel2000 rdaniel2000 is offline
Miembro
 
Registrado: jun 2003
Posts: 11
Poder: 0
rdaniel2000 Va por buen camino
Cita:
Empezado por duilioisola Ver Mensaje
Prueba con esta versión:
Notarás que hay una variable mas "P2" de tipo PChar.
Quizas la asignación directa del resultado de inet_ntoa que es PChar a String no le gusta.

Código Delphi [-]
function DameIPLocal: string;
var
  p : PHostEnt;
  s : array[0..128] of char;
  p2 : PChar;
  wVersionRequested : word;
  wsaData : TWSAData;
begin
  // Arranca la librería WinSock
  try
     wVersionRequested := MAKEWORD(1, 1);
     WSAStartup(wVersionRequested, wsaData);

     // Obtiene el nombre del PC
     GetHostName(@s, 128);
     p := GetHostByName(@s);

     // Obtiene la dirección IP y libera la librería WinSock
     p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
     if (Assigned(p2)) then
        Result := Result + p2
     else
        Result := '';
     WSACleanup;
  except
    on E: Exception do
      Result := E.Message;
  end;
end;


Le agregue a tu funcion el Mensaje de Excepcion para saber si aun continua y desafortunadamente la Excepcion persiste.
Responder Con Cita
  #13  
Antiguo 06-11-2017
rdaniel2000 rdaniel2000 is offline
Miembro
 
Registrado: jun 2003
Posts: 11
Poder: 0
rdaniel2000 Va por buen camino
Confirmado, Instale Windows Server 2016 Version 1607 (Compilacion de SO 14393.0)

Usando el ISO, sin aplicar ninguna actualizacion de Windows y el Error se presenta al obtener el IP, y ademas de eso muchos otros errores con los componentes de Delphi.

Procedi a Actualizar Windows (KB4035631)

Y con esta actualizacion ya funcionan todas las Funciones anteriores...

Como lo habia dicho, la Instalacion por default de Windows tiene errores que han sido corregidos por Micro$oft.


Saludos,.
Responder Con Cita
  #14  
Antiguo 24-11-2017
Vero190 Vero190 is offline
Registrado
NULL
 
Registrado: nov 2017
Posts: 4
Poder: 0
Vero190 Va por buen camino
Justo lo que necesitaba! Gracias!
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Conexion a servidor dedicado windows server y sql server ValentinoP MS SQL Server 3 23-01-2017 19:14:37
SQL Server 2000 vs Windows Server 2008 Enterprise lgarcia MS SQL Server 9 31-08-2016 20:10:58
Conectar a SQL Server y Windows 2003 Server Punzo MS SQL Server 2 11-12-2007 21:30:40
Windows Media Server e Internet Information Server Ñuño Martínez Windows 0 08-09-2006 12:26:53
Compartir recursos entre Windows Nt Server y Windows 98 fer21unmsm Windows 1 18-07-2006 23:05:44


La franja horaria es GMT +2. Ahora son las 16:00:31.


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