请问,能不能在VC程序中获得本机上网后的动态IP地址,如果可以,请问,如何实现呢

解决方案 »

  1.   

    http://search.csdn.net/expert/topic/50/5001/2002/6/29/837852.htm
      

  2.   

    http://www.codeproject.com/internet/ipenum.asp
      

  3.   

    GetIpAddrTable
    The GetIpAddrTable function retrieves the interface–to–IP address mapping table.DWORD GetIpAddrTable(
      PMIB_IPADDRTABLE pIpAddrTable,  // buffer for mapping table 
      PULONG pdwSize,                 // size of buffer 
      BOOL bOrder                     // sort the table 
    );MIB_IPADDRTABLE
    The MIB_IPADDRTABLE structure contains a table of IP address entries.typedef struct _MIB_IPADDRTABLE {
      DWORD         dwNumEntries;    // number of entries in the table
      MIB_IPADDRROW table[ANY_SIZE]; // array of IP address entries
    } MIB_IPADDRTABLE, *PMIB_IPADDRTABLE;MIB_IPADDRROW
    The MIB_IPADDRROW specifies information for a particular IP address.typedef struct _MIB_IPADDRROW {
      DWORD   dwAddr;              // IP address
      DWORD   dwIndex;             // interface index
      DWORD   dwMask;              // subnet mask
      DWORD   dwBCastAddr;         // broadcast address 
      DWORD   dwReasmSize;         // rassembly size 
      unsigned short   unused1;    // not currently used 
      unsigned short   unused2;    // not currently used 
    } MIB_IPADDRROW, *PMIB_IPADDRROW;
      

  4.   

    CString GetCurrentIP()
    {
    char name[100];
    ::gethostname (name,100);
    hostent *host=gethostbyname((const char *)name);
    if(host==NULL)//dns查询错误
    {
    return "";
    }
    else
    {
    in_addr addr; 
    memcpy((void*)&addr.S_un .S_addr ,*host->h_addr_list,sizeof(in_addr)); 
    return CString(inet_ntoa (addr));
    }
    }