同上

解决方案 »

  1.   

    gethostname
    gethostbyname============================================================================
    http://www.betajin.com/alphasun/index.htm
    DocWizard C++程序文档自动生成工具 | Wave OpenGL | HttpProxy | AjaxParser词法分析
      

  2.   

    //取得网卡全部信息
    GetAdaptersInfo();//详见MSDN
    Windows NT/2000: Requires Windows 2000.
      Windows 95/98: Requires Windows 98.
      Header: Declared in Iphlpapi.h.
      Library: Use Iphlpapi.lib.
      

  3.   

    void GetIP()
    {
    CString str;
        char szhostname[128];
    if( gethostname(szhostname, 128) == 0 )
    {
    struct hostent * phost;
        int i;
     
         phost = gethostbyname(szhostname);//如果知道主机名就省掉前面的
     
         for( i = 0; phost!= NULL && phost->h_addr_list[i]!= NULL; i++ )
    {
           int j;
     
            for( j = 0; j<phost->h_length; j++ )
    {
    CString addr;
       
          if( j > 0 )
      str += ".";
     
           addr.Format("%u", (unsigned int)((unsigned
         char*)phost->h_addr_list[i])[j]);
         str += addr;
    }
    }
    }
    AfxMessageBox("你的IP地址为:"+str+"!");
    }