IP Enumeration
Posted
by Yvo van Dillen
on December 24th, 2003
Environment: VC4, VC5, VC6
I think this is the quickest way to enumerate the available IP addresses on your machine. I've gotten this question a lot. This is fairly simple but haven't seen it anywhere.
IP Enumeration
// Function GetIPs // in : CStringArray // out : CStringArray + count int GetIPs( CStringArray &arrIPS ) { BOOL bRet = TRUE; char name[255]; int i=0; PHOSTENT hostinfo; //first, clear the list arrIPS.RemoveAll(); //get the host name if( gethostname ( name, sizeof(name)) == 0) { // get the host info if((hostinfo = gethostbyname(name)) != NULL) { // now, loop until the address list = null while( hostinfo->h_addr_list[i] != NULL ) { //get the IP address char *ip_addr = inet_ntoa (*(struct in_addr *) hostinfo->h_addr_list[i]); //add it to the array ip_addr ); //increment the counter i++; } } } //return the array count return arrIPS.GetSize(); }

Comments
Don't forget to call WSAStart()...
Posted by Legacy on 12/30/2003 12:00amOriginally posted by: David Little
ReplyGOOD BOY
Posted by Legacy on 12/24/2003 12:00amOriginally posted by: Best Programmer
YES THIS IS THE QUICKEST WAY.....YOU GET THE AWARD FOR THE QUICKY OF THE YEAR
Reply