#include "winsock2.h" (需要WS2_32.LIB库文件)
CString strIp[10];
int nCount = 0;
WORD wversionrequested;
WSADATA wsadata;
char name[255];
wversionrequested = MAKEWORD(2, 0);
//调用WinSock2功能之前必须调用WSAStartup
if( WSAStartup(wversionrequested, &wsadata ) == 0 ){
if( gethostname( name, sizeof( name )) == 0){
PHOSTENT hostinfo;
hostinfo = gethostbyname(name);
for( int i = 0; hostinfo != NULL && hostinfo->h_addr_list[i] != NULL; i++){
strIp[i] = inet_ntoa(*(struct in_addr*)hostinfo->h_addr_list[i]);
nCount ++;
}
}
WSACleanup();
}