Jak w Label wyświetlić numer IP (BCB)
0
0
jest to funkcja pobierajaca nr ip z mojego programiku :
String GetIP(void)
{
String nrIP;
WSAData wsaData;
char hname[128];
/* inicjalizacja Windows Socktes DLL */
if( WSAStartup(MAKEWORD(1,1),&wsaData) != 0 )
{
MessageBox(0,"Nie moge zaladowac modulu Windows Sockets DLL!",
"Program",MB_OK | MB_ICONERROR);
}
else
{
gethostname(hname,sizeof(hname)); // pobranie nazwy hosta
/* zapisanie nr. IP do struktury hostent na podst. nazwy hosta */
hostent * phe = gethostbyname(hname);
/* zapisanie nr. IP do stringa za pomoca funkcji inet_ntoa */
nrIP = AnsiString(inet_ntoa(*(in_addr*)*phe->h_addr_list));
}
return nrIP;
}
0
Oj Kamil,Kamil tak :
#include
w onClick Buttona :
char buff[100];
hostent *lphe;
WSADATA WSAData;
WSAStartup(MAKEWORD(2, 0), &WSAData);
gethostname(buff, 100);
lphe = gethostbyname(buff);
Label1->Caption = AnsiString(inet_ntoa((in_addr)*lphe->h_addr_list));
WSACleanup();