title image


Smiley Re: Wie finde ich die IP-Adresse meines Providers, bei dem ich surfe raus??
#include Link mit Wsock32.lib { WORD wVersionRequested; WSADATA wsaData; char name[255]; CString ip; PHOSTENT hostinfo; wVersionRequested = MAKEWORD( 2, 0 ); if ( WSAStartup( wVersionRequested, &wsaData ) == 0 ) { if( gethostname ( name, sizeof(name)) == 0) { if((hostinfo = gethostbyname(name)) != NULL) { ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list); } } WSACleanup( ); } }Following is a code that gets local machine IP addresses. The advantages over the article by Jeff Lundgren are that my code recognises ALL IP addresses and is ready for IPv6 ;-) char szHostName[128];if( gethostname(szHostName, 128) == 0 ){ // Get host adresses struct hostent * pHost; int i; pHost = gethostbyname(szHostName); for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ ) { CString str; int j; for( j = 0; j h_length; j++ ) { CString addr; if( j > 0 ) str += "."; addr.Format("%u", (unsigned int)((unsigned char*)pHost->h_addr_list[i])[j]); str += addr; } // str now contains one local IP address - do whatever you want to do with it (probably add it to a list) }}

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: