我用的是学校宽带上网,一个组的机器可以互联,但地址是自动分配,无法查看,我想在程序中获取本机的地址应该怎么办?

解决方案 »

  1.   

    调用下面
    CString GetIp()
    {
      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( );
          } 
      return ip;
    }
      

  2.   

    上面的两位没有考虑多接口主机的情况.
    在多接口主机的情况下应该用:
    RasEnumConnections
    RasGetProjectionInfo
    去获得IP地址信息.
      

  3.   

    有这么高手帮我,实在是感激不尽。小生想问一下,上面使用的函数都是 API 函数?还是别的?我的硬盘空间不够大,没有安装MSDN