R. Porcar Site Admin

Registrado: 08 Ago 2002Mensajes: 113Ubicación: Castellón (España)
|
Publicado: Vie 16 Ago, 2002 9:54 am Asunto: Conocer la IP |
|
|
| Código: | #include <winsock2.h>
// ...
void __fastcall TForm1::Button1Click(TObject *Sender)
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
AnsiString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
Label1->Caption = name;
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(in_addr *)*hostinfo->h_addr_list);
Label2->Caption = ip;
}
}
WSACleanup( );
}
} |
|
|