一些关于vc的问答

源代码在线查看: subject_18748.htm

软件大小: 8176 K
上传用户: RSY527
关键词: 问答
下载地址: 免注册下载 普通下载 VIP

相关代码

				
				序号:18748 发表者:lijianhua 发表日期:2002-10-23 11:43:13
				主题:如何获得局域网内部所有的计算机名称。求教
				内容:请详细说明。
				返回上页访问论坛
				
				
				答案被接受回复者:徐景周 回复日期:2002-10-23 11:44:54
				内容:20.    如何获取局域网上计算机名及它们的IP地址l    连接ws2_32.lib和 mpr.lib库l    #include winsock2.hCString strTemp;struct hostent *host;struct in_addr *ptr; // 检索IP地址 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];    unsigned int i;    for ( 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];                                    // =. 分隔开IP:211.40.35.76.                             int a = ptr->S_un.S_un_b.s_b1;  // 211                           int b = ptr->S_un.S_un_b.s_b2;  // 40                int c = ptr->S_un.S_un_b.s_b3;  // 35                int d = ptr->S_un.S_un_b.s_b4;  // 76                strTemp.Format("%s -->  %d.%d.%d.%d",                    strFullName,a,b,c,d);                AfxMessageBox(strTemp);            }        }    }    delete Buffer;    WNetCloseEnum( hEnum ); }WSACleanup();参看:http://www.copathway.com/itbookreview/view_paper.asp?paper_id=363
				
				返回上页访问论坛
				
				
				回复者:小不点 回复日期:2003-02-09 10:07:23
				内容:徐景周大哥,为什么这个程序只能列举一部分IP地址?其余的我在“网上邻居”上能看见,但是没有显示出来,特别是使用汉字命名的计算机看不到。
				
				返回上页访问论坛
							

相关资源