// Get ip list
struct hostent* phe;
CString strIp, strTemp;
strIp.Empty ();
phe = gethostbyname (cHost);
if (NULL == phe)
{
strErr.Format ("Socket Error: %d", WSAGetLastError ());
MessageBox (strErr, "Socket Error");
} for (int i = 0; phe->h_addr_list[i]; ++i)
{
struct in_addr in;
memcpy (&in, phe->h_addr_list[i], sizeof (struct in_addr));
strTemp.Format ("Address[%d]: ", i);
strTemp += inet_ntoa (in);
strIp += strTemp;
strIp += "\n";
strTemp.Empty ();
}

解决方案 »

  1.   

    for (int i = 0; phe->h_addr_list[i]; ++i)多穴主机IP....搜索“多穴”能找到很多...
      

  2.   

    int GetSelfIp(CString strIp[])
    {
    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( );

    return nCount;
    }