Click to See Complete Forum and Search --> : List of domains or users in the network


Eric3k
October 24th, 2003, 09:46 AM
Hi,
Is there an API or a way to get a list of all the users logged into the local network (or their domains)?
Thanks

Black_Daimond
October 24th, 2003, 10:48 AM
i was searching for the same thing ,someone sent me this peace of code i tried it and it works !!

struct HostInfo
{
char *csName;
char *csAdr;
char *csComment;
};
struct hostent *host;
struct in_addr *ptr; // To retrieve the IP Address
DWORD dwScope = RESOURCE_CONTEXT;
NETRESOURCE *NetResource = NULL;
HANDLE hEnum;
WNetOpenEnum(dwScope, NULL, NULL, NULL, &hEnum);
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2),&wsaData);
UINT item = 0;
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 (UINT i = 0; i < BufferSize/sizeof(NETRESOURCE); i++, NetResource++)
{
if (NetResource->dwUsage == RESOURCEUSAGE_CONTAINER && NetResource->dwType == RESOURCETYPE_ANY)
{
if (NetResource->lpRemoteName)
{
CString strFullName = NetResource->lpRemoteName;

char buf[512];

if (0 == strFullName.Left(2).Compare("\\\\"))
strFullName = strFullName.Right(strFullName.GetLength()-2);

gethostname(szHostName, strlen( szHostName ));

host = gethostbyname(strFullName);

if (!host)
continue;

ptr = (struct in_addr *) host->h_addr_list[0];

sprintf(buf, "%d.%d.%d.%d", ptr->S_un.S_un_b.s_b1,
ptr->S_un.S_un_b.s_b2, ptr->S_un.S_un_b.s_b3, ptr->S_un.S_un_b.s_b4);
if(strcmp(buf,adr))
{
HostInfo hInfo;//a struct that i made inorder to put info in
hInfo.csName = new char[strlen(strFullName)+1];
strcpy(hInfo.csName,strFullName);
hInfo.csAdr = new char[strlen(buf)+1];
strcpy(hInfo.csAdr,buf);
hInfo.csComment = new char[strlen(NetResource->lpComment)+1];
strcpy(hInfo.csComment,NetResource->lpComment);
//do something with the struct and delete it after }
}
}
}
MyDelete(Buffer);
WNetCloseEnum(hEnum);
}
WSACleanup();

Eric3k
October 24th, 2003, 11:14 AM
Cool, I'll try that. Thanks alot!

poorni
April 22nd, 2004, 03:39 AM
hi,
I tried the above given code but its giving some error.Can anyone tell me how to get the list of users connected to the network?
Thanks in advance,
Poorni

Andreas Masur
April 22nd, 2004, 04:21 AM
[Moved thread]

Black_Daimond
April 22nd, 2004, 04:50 AM
tried the above given code but its giving some error what kind of errors it's giving??

poorni
April 22nd, 2004, 06:41 AM
Actually the main problem with that code is that its displaying the names of the machines in the same workgroup i.e My machine is connected to a workgroup which had 3 systems and the above code is displaying only these 3 names.I want all the machines in the network to be displayed .Plz help me

Thanx in advance
Poorni

Black_Daimond
April 22nd, 2004, 06:50 AM
try this :
passe RESOURCE_GLOBALNET as first params of WNetOpenEnum

poorni
April 22nd, 2004, 09:12 AM
hi
i tried the option but its not displaying any of the computer names i have attached the file with this reply.Can u plz go through it and tell me whats the problem why its not displaying?

Thanks in advance
Poorni

Black_Daimond
April 22nd, 2004, 12:20 PM
i attached a zip that conatins the code of an app that enumerate all users connected to a network ,i think it's enough explained but if u don't understand some thing let me know about it!!!

poorni
April 23rd, 2004, 05:42 AM
hi ,
Thanx a lot for ur code..I had names of all machines in a network.I basically want to send message to the users whoever i select (something like chat or net send) so i am trying with ur code and tell u if its working......Plz help me in establishing connection and also sending messages to the selected users........


Thanx in advance
Poorni

Black_Daimond
April 23rd, 2004, 05:50 AM
take a look at this code

poorni
April 23rd, 2004, 09:14 AM
Hi,
Thanx for ur code...but i need a single application which can act as server and also client.Actually it is suppose to work like this:
Whenever i execute the application it should be in the listening mode and also displays the list of users connected in my network.So this application which is being executed in other machines also will be in listening mode..So if i select any user connection should be established between the two and message should be transfered between them.Its like any user can communicate with any number of users at the same time.Plz tell me is it possible to create such an application

Thanx in advance
Poorni

Black_Daimond
April 23rd, 2004, 10:27 AM
sure u could do it,my first idea is to create an application with 2 separated thread:the first thread will act as server (listning mode )the second will be the client....

poorni
April 24th, 2004, 12:40 AM
Hi,
Thanx again for ur immediate response.I have attached my program in which i have tried the same program but without using thread.....Its giving me error while connecting to the client itself can u just see the program and tell me whats wrong with that.I have never used threads in programming and have no idea where to start with.Plz help me

Thanx in advance
Poorni

Black_Daimond
April 28th, 2004, 05:35 AM
i can't see the probleme from this single file ,can you send the project so i can test is and see what's wrong with it??

poorni
April 28th, 2004, 08:45 AM
hi,
Thanx for ur reply.I have attached my project .Plz go thro it and tell me the errors

Thanx in advance
Poorni

Black_Daimond
April 29th, 2004, 11:53 AM
to say the truth i can't read other's code :blush: so i decide to do an application that fit what u asked me about !!! i based my app on NDK classes it's a single app that can connect to other hosts and in the same time can be server to other hosts i hope that will help u!!!!
don't hesitate to ask me if u don't understand some thing :D

poorni
April 30th, 2004, 08:21 AM
Thanx for ur code.I will see it and let u know abt it

Thanx again
Poorni

poorni
May 6th, 2004, 12:23 AM
hi,
Thanx for ur code .but its really too big to understand.i am trying to understand ur code....will tell u next week abt it...
Thanx again for ur code.............


Poorni