Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
C++
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);
Posted
Updated 5-Jan-11 4:42am
v2
Comments
Gokulnath007 5-Jan-11 8:28am    
Anybody there for helping me???

1 solution

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).
 
Share this answer
 
Comments
Gokulnath007 5-Jan-11 7:58am    
Yeah.. I want to list all the ip addresses (or) the system names inside the Network(LAN) in which my application is running there.. Its like a chat application..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900