谢谢

解决方案 »

  1.   

    进入dos命令方式,输入命令:
    ipconfig /all
    回车,即可获得本机的ip地址,并能知道本机网卡的物理地址。
      

  2.   

    Platform SDK: Internet Protocol Helper
    GetAdaptersInfo()typedef struct _IP_ADAPTER_INFO {
      struct _IP_ADAPTER_INFO* Next;
      DWORD ComboIndex;
      char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
      char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
      UINT AddressLength;
      BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];
      DWORD Index;
      UINT Type;
      UINT DhcpEnabled;
      PIP_ADDR_STRING CurrentIpAddress;//**
      IP_ADDR_STRING IpAddressList;
      IP_ADDR_STRING GatewayList;
      IP_ADDR_STRING DhcpServer;
      BOOL HaveWins;
      IP_ADDR_STRING PrimaryWinsServer;
      IP_ADDR_STRING SecondaryWinsServer;
      time_t LeaseObtained;
      time_t LeaseExpires; 
    } IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;
      

  3.   

    先 gethostname 获得本机机器名,
    再 gethostbyname 获得IP等信息。
      

  4.   

    抢分!! 需要ws2_32.lib ,和#include <winsock2.h>CString ip;
    WORD wVersionRequested; 
    WSADATA wsaData; 
    char name[255]; 
    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( ); 
    }

    if (ip.IsEmpty())
    {
      ip = "127.0.0.0";
    }
      

  5.   

    char csPcName[MAX_PCNAME_LEN];
    if (SOCKET_ERROR == gethostname (csPcName, MAX_PCNAME_LEN))
    {
    TRACE0("GetComputerNameError!");
    return 0;
    }

    hostent* pHst = gethostbyname(csPcName);
    if ( NULL == pHst )
    {
    TRACE0("GetHostIPAddressByName Error!");
    return 0;
    } DWORD dwIpAddress = *(DWORD*)pHst->h_addr_list[0];