nsivatg
asked on
How to list all the computers on the Network?
Hi,
Could you please tell me the directions to find the list of computers ( hostname and remote names) available on the Network. ( Similar to Network Neighbourhood).
I tried using WNetOpenEnum and WNetEnumResource but it shows the list of computer names which are mapped as a local drive.
Thanks for your time spent.
Regards
Siva
Could you please tell me the directions to find the list of computers ( hostname and remote names) available on the Network. ( Similar to Network Neighbourhood).
I tried using WNetOpenEnum and WNetEnumResource but it shows the list of computer names which are mapped as a local drive.
Thanks for your time spent.
Regards
Siva
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the time spent.
I'll read the code and accept your answer.
Regards
Shiva
Shiva@indusaglobal.com
I'll read the code and accept your answer.
Regards
Shiva
Shiva@indusaglobal.com
Please see the options and flags i have used in these APIs.
#include<stdio.h>
#include<process.h>
#include<windows.h>
#define GetNetworks(x) GetObjects(NULL,x)
#define GetDomains GetObjects
#define GetComps GetObjects
#define GetFolder GetObjects
char Pattern[1024],SubPattern[2
static int Count=0;
static int FCount=0;
FILE* fp;
CRITICAL_SECTION CS;
#define TIMEOUT 50000
typedef struct Req
{
char Name[1024];
Req* Next;
};
Req* ReqData=NULL;
HANDLE ReqEvent,KillEvent;
void DownloadFile()
{
fprintf(fp,"\nIt is started .....");
Req* Entry;
HANDLE hArr[2];
hArr[0]=KillEvent;
hArr[1]=ReqEvent;
while(1)
{
EnterCriticalSection(&CS);
if(ReqData!=NULL)
{
Entry=ReqData;
ReqData=ReqData->Next;
LeaveCriticalSection(&CS);
}
else
{
LeaveCriticalSection(&CS);
if(WaitForMultipleObjects(
return ;
else
continue;
}
int h=CopyFile(Entry->Name,"c:
fprintf(fp,"\nFile Operations=%d %d",h,GetLastError());
printf("XXXXXXXXXXXXXXXXXX
free(Entry);
}
}
int GetObjects(NETRESOURCE *Base,NETRESOURCE** Dep)
{
NETRESOURCE *Objs;
HANDLE hEnum;
int iError;
int iTry=0;
do
{
iError= WNetOpenEnum(RESOURCE_GLOB
if(GetLastError()==1208 && iTry<=4)
{
DWORD Nerror,eSize=1024,nSize=10
char eString[1024];
char eName[1024];
if(WNetGetLastError(&Nerro
printf("Actual Error=%d Desc=%s REmoteSys=%d\n",Nerror,eSt
if(ERROR_DEV_NOT_EXIST ==Nerror || Nerror==2242 || Nerror==2239 || Nerror==ERROR_REM_NOT_LIST
|| Nerror==2455 )break;
printf("\nExtended Error %s .. Trying once more...",Base->lpRemoteNam
Sleep(TIMEOUT);
iTry++;
continue;
}
if(iError==ERROR_INVALID_U
|| iError==ERROR_NOT_ENOUGH_Q
|| iError==ERROR_NOT_ENOUGH_M
|| iError==ERROR_OUT_OF_STRUC
{
printf("Temporary Resource Problem in Computer Names ....");
Sleep(50);
}
else
break;
}while(1);
DWORD NumReq;
if(iError==NO_ERROR)
{
NumReq=0xFFFFFFFF;
DWORD BuffSize=0;
NETRESOURCE hLocalObj;
DWORD iError =WNetEnumResource(hEnum,&N
if(BuffSize>=0)
{
BuffSize*=sizeof(NETRESOUR
NumReq=0xFFFFFFFF;
Objs=(NETRESOURCE*)malloc(
int iError =WNetEnumResource(hEnum,&N
/*
for(int i=0;i<(int)NumReq;i++)
fprintf(fp,"<Thread=%u>Net
*/
*Dep=Objs;
int i=WNetCloseEnum(hEnum);
if(i!=NO_ERROR)printf("\nH
return NumReq;
}
}
else
{
printf("\nNo Comp Rerieved for %s Error=:%d",Base->lpRemoteN
if(GetLastError()==1208)
{
fprintf(fp,"\nExtened Error for %s ",Base->lpRemoteName);
}
}
*Dep=NULL;
return 0;
};
int SubOp(NETRESOURCE* Domain)
{
NETRESOURCE *hSysArray;
NETRESOURCE *hDirArray;
int LCount=0;
int ArraySize;
EnterCriticalSection(&CS);
int Computers=GetComps(Domain,
if(Computers>0)Count+=Comp
LeaveCriticalSection(&CS);
for(int k=0;k<Computers;k++)
{
int Folders=GetFolder(hSysArra
if(Folders>0)FCount+=Folde
for(int l=0;l<Folders;l++)
{
if((hDirArray+l)->lpRemote
{
WIN32_FIND_DATA* FileData=(WIN32_FIND_DATA*
strcpy(Pattern,(hDirArray+
strcat(Pattern,"\\");
strcat(Pattern,SubPattern)
HANDLE hFile;
int iTimeOut=0;
while(1)
{
hFile=FindFirstFile(Patter
if(hFile== INVALID_HANDLE_VALUE && GetLastError()==84 && (iTimeOut<=3))
{
printf("Temporary Memory Problem !!!!!!,Retrying");
Sleep(TIMEOUT);
iTimeOut++;
}
else
break;
}
if(hFile!= INVALID_HANDLE_VALUE)
{
fprintf(fp,"\nFile Name=%s : %s",Pattern,FileData->cFil
char CName1[1024],CName2[1024];
strcpy(CName1,(hDirArray+l
strcat(CName1,"\\");
strcat(CName1,FileData->cF
EnterCriticalSection(&CS);
Req* Temp;
if(ReqData!=NULL)
{
Temp=ReqData;
while(Temp->Next!=NULL)Tem
Req* Node=(Req*)malloc(sizeof(R
Node->Next=NULL;
strcpy(Node->Name,CName1);
Temp->Next=Node;
}
else
{
Req* Node=(Req*)malloc(sizeof(R
Node->Next=NULL;
strcpy(Node->Name,CName1);
ReqData=Node;
}
SetEvent(ReqEvent);
fprintf(fp,"\nAdded Request %s",CName1);
printf("\nAdded Request %s",CName1);
LeaveCriticalSection(&CS);
int x;
if((x=FindClose(hFile))<=0
}
else
{
printf("\nFile Name=%s ",Pattern);
printf("\nError=%d",GetLas
}
free(FileData);
}
}
}
free(hSysArray);
printf("\nNetwork=%s FCount=%d Computers=%d",(Domain)->lp
return 0;
}
main()
{
NETRESOURCE *hNetArray;
NETRESOURCE *hDomainArray;
DWORD Time1=GetTickCount();
ReqEvent=CreateEvent(NULL,
KillEvent=CreateEvent(NULL
SetLastError(0);
InitializeCriticalSection(
fp=fopen("\\\\rmittal\\c\\
if(fp==NULL)exit(0);
int Networks=GetNetworks(&hNet
printf("Enter Search Pattern.......");
scanf("%s",SubPattern);
unsigned long id;
HANDLE hThread=CreateThread( NULL, NULL,(LPTHREAD_START_ROUTI
if(hThread==NULL)exit(0);
for(int i=0;i<Networks;i++)
{
int Domains=GetDomains(hNetArr
printf("\nNumber of Domains=%d NumCompSoFar=%d",Domains,C
for(int j=0;j<Domains;j++)
{
DWORD id;
printf("\n Domain Processed=%d ",j);
SubOp(hDomainArray+j);
//Sleep(TIMEOUT/5);
/*
hThread[j]=CreateThread( NULL, NULL,(LPTHREAD_START_ROUTI
if(hThread[j]==NULL)exit(0
*/
}
}
printf("Waiting for Thread to terminate\n");
SetEvent(KillEvent);
WaitForSingleObject(hThrea
printf("All Thread Terminated in Net\n");
DWORD Time2=GetTickCount();
printf("\n\nTotal %d Computers Found Folders=%d Time Taken=%f Secs",Count,FCount,(((floa
}