目的:得到局域网中的每台机器IP
方法:DWORD dwRet = GetAdaptersInfo((PIP_ADAPTER_INFO)&tempChar, &uListSize);
问题: 现在得到的是和连接网关的外网的IP,而不是内部的列表
     如何能得到内网的IP列表??

解决方案 »

  1.   

    有个傻方法,把这个网段的所有ip ping一遍
      

  2.   

    to orbit(吹泡泡的小猫) 
     寒!这个太慢了
      

  3.   

    to _xiao(小小)
      我就是读arp表得出的外网的IP,而不是内网的
    to huangxiaoke2000(小小) 
      如何用arp广播?
      

  4.   

    先用WnetEnumResource 对网络资源进行枚举。
    再用Gethostname获得主机名
    再用Gethostbyname得到相关数据,可以从中得到IP地址。用这些东西要先调用WSAStartup函数, 枚举完了用WnetCloseEnum结束,最后调用WSAClearup结束调用Winsock.dll
      

  5.   

    to coolmei25(梅生) 
      这样能得到局域网中所有机器的ip吗?
      
      

  6.   

    void CListNeighborDlg::OnOK() 
    {
    GetDlgItem(IDOK)->EnableWindow(FALSE); CStringArray list;
    EnumHosts(list); CListBox *pList = (CListBox *)GetDlgItem(IDC_LIST);
    pList->ResetContent(); for(int i=0; i<list.GetSize(); i++)
    {
    pList->AddString(list.GetAt(i));
    } GetDlgItem(IDOK)->EnableWindow(TRUE);// CDialog::OnOK();
    }
    void CListNeighborDlg::EnumHosts(CStringArray &list)
    {
    list.RemoveAll(); CString strTemp;
    struct hostent *host;
    struct in_addr *ptr; DWORD dwScope = RESOURCE_CONTEXT;
    NETRESOURCE *NetResource = NULL; HANDLE hEnum; WNetOpenEnum(dwScope, NULL, NULL, NULL, &hEnum); WSADATA wsaData;
    WSAStartup(MAKEWORD(1,1), &wsaData); if(hEnum)
    {
    DWORD Count = 0xFFFFFFFF;
    DWORD BufferSize = 2048; LPVOID Buffer = new char[2048]; WNetEnumResource(hEnum, &Count, Buffer, &BufferSize); NetResource = (NETRESOURCE *)Buffer; char szHostName[200]; for (unsigned int i=0; i<BufferSize/sizeof(NETRESOURCE); i++, NetResource++)
    {
    if (NetResource->dwUsage == RESOURCEUSAGE_CONTAINER && NetResource->dwType == RESOURCETYPE_ANY)
    {
    if (NetResource->lpRemoteName)
    {
    CString strFullName = NetResource->lpRemoteName; if (0 == strFullName.Left(2).Compare("\\\\"))
    strFullName = strFullName.Right(strFullName.GetLength() - 2); gethostname(szHostName, strlen(szHostName)); host = gethostbyname(strFullName); if (host == NULL) continue; ptr = (struct in_addr *)host->h_addr_list[0]; int a = ptr->S_un.S_un_b.s_b1;
    int b = ptr->S_un.S_un_b.s_b2;
    int c = ptr->S_un.S_un_b.s_b3;
    int d = ptr->S_un.S_un_b.s_b4; strTemp.Format("%s -->  %d.%d.%d.%d", strFullName, a,b,c,d); list.Add(strTemp); } }
    } delete Buffer;
    WNetCloseEnum(hEnum);
    }

    WSACleanup();}
      

  7.   

    果然好用,
    想得到Mac地址用哪一个函数?
    多谢!!
      

  8.   

    不知道,看书上说是要调用NetApi32.dll
    在网上查把!
      

  9.   

    http://www.pcvc.net/category/content.asp?sendid=229