越简单越好阿
要以***.***.***.***格式保存的

解决方案 »

  1.   

    char *GetLocalIP()
    {
       struct in_addr localaddr;
       struct hostent *hp=NULL;
       char hostname[50];
       gethostname(hostname,49);//主机名
       hp=gethostbyname(hostname);主机信息
       memcpy(&localaddr,hp->h_addr,hp->length);//地址
       return inet_ntoa(localaddr);//变成char *}
      

  2.   

    用这个很简单,GetAdphterInfo(),呵,一下得到了
      

  3.   

    用gethostbyname()
    完全同意SeainBlue(爱海)的办法
      

  4.   

    很多方法,ip helper api可以
    楼上的几位方法也都很好
      

  5.   

    void CListCtrl1Dlg::OnButton1() 
    {
    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( );

    AfxMessageBox(name);//name里是本机名
    AfxMessageBox(ip); //ip中是本机IP
    }
      

  6.   

    #include <winsock2.h>
    #include <windows.h>char* GetLocalIP(void)
    {
    WSADATA wsadata;
    char szHostName[MAX_PATH + 1] = "\0";
             hostent *phe;
    in_addr myip; if (WSAStartup(MAKEWORD(2,2), &wsadata) != 0)
    {
    return NULL;
    }
        
             if(gethostname(szHostName, MAX_PATH ) == 0)
    {
    phe = gethostbyname(szHostName);
    memcpy((char*)&myip, phe->h_addr_list[0], 4);
    WSACleanup();
    return (inet_ntoa(myip));

    }
    else
    {      
                       WSACleanup();
     return NULL;
             }    
       
    }
      

  7.   

    extern "C" __declspec(dllexport) char* WINAPI GetLocalIPAddr()

    WORD wVersionRequested;
    WSADATA wsaData;
    char name[255];
    CString strIP;
    PHOSTENT hostinfo;
    wVersionRequested = MAKEWORD( 2, 0 );

    if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
    {
    if( gethostname ( name, sizeof(name)) == 0)
    {
    if((hostinfo = gethostbyname(name)) != NULL)
    {
    strIP = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
    }
    }   
    WSACleanup( );
    } char* pszLocalIPAddr;
    pszLocalIPAddr=new char[strIP.GetLength()+1];
    strcpy(pszLocalIPAddr,(LPCSTR)strIP);
    return pszLocalIPAddr;
    }