[已解决]获取所有系统名称 [英] [Solved] Getting all systems name

查看:156
本文介绍了[已解决]获取所有系统名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用VC ++ MFC在办公室内部获取局域网中的所有系统名称.基于对话框的应用程序以及如何在列表控件中列出名称...请帮助我.. :(

修改[OP的答案] :
我自己找到了解决方案.

How to get all the system names in the LAN .. may be inside an office using VC++ MFC. Dialog Based application and how to list the names in the list control...Pls Help Me.. :(

Modification [OP''s anwswer]:
I found the solution myself.

m_ListCtrl->InsertColumn(0,_T("Name"),0,130);
	LPSERVER_INFO_101 pBuf = NULL;
	LPSERVER_INFO_101 pTmpBuf;
	DWORD dwLevel = 101;
	DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
	DWORD dwEntriesRead = 0;
	DWORD dwTotalEntries = 0;
	DWORD dwTotalCount = 0;
	DWORD dwServerType = SV_TYPE_ALL; // all servers
	DWORD dwResumeHandle = 0;
	NET_API_STATUS nStatus;
	wchar_t *pszServerName = NULL;
	DWORD i;	//
	pszServerName = L"\\\\cgdomain.com"; // replace it with yours
	nStatus = NetServerEnum(pszServerName,dwLevel,(LPBYTE *) &pBuf,dwPrefMaxLen,&dwEntriesRead,&dwTotalEntries,dwServerType,NULL,&dwResumeHandle);
	if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
	{
		if ((pTmpBuf = pBuf) != NULL)
		{	
			for (i = 0; i < dwEntriesRead; i++)
			{
				if (pTmpBuf == NULL)
				{
					break;
				}
				char szTxt[MAX_PATH]={0};
				::WideCharToMultiByte( CP_ACP, 0,pTmpBuf->sv101_name,-1, szTxt,MAX_PATH, NULL, 0);
				CString strValue,strTemp1,strTemp2;
				strValue=szTxt;
				strTemp1=strValue.GetAt(0);
				strTemp2=strValue;
				strTemp2.Delete(0);
				strTemp2.MakeLower();
				strValue="";
				strValue=strTemp1+strTemp2;				
				m_ListCtrl->InsertItem(i,strValue);
				pTmpBuf++;
				dwTotalCount++;
			}
		}
	} 
	else
		AfxMessageBox(_T("A system error has occurred"));
	if (pBuf != NULL)
		NetApiBufferFree(pBuf);

推荐答案

您需要检索正在运行应用程序的系统的网络掩码,然后获取IP地址,然后遍历所有可能的IP,向每个可能的IP发送一个ICMP数据包(基于netmask/IP).
You need to retrieve the net mask of the system you''re app is running on, then the IP address, and then iterate through all the possible IPs send an ICMP packet to each possible IP (based on netmask/IP).


这篇关于[已解决]获取所有系统名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆