Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

Scanning Network to get computer names

How do I scan a network to get computer names.  Not the users logged on.  Just computer names.  
0
strongd
Asked:
strongd
  • 5
  • 4
  • 2
  • +3
1 Solution
 
chitnisCommented:
use MAPI/ISAPI books.
0
 
athakur999Commented:
You can use the "NET VIEW" command, redirect the output to a file, and parse through the file to get a list of names.  If I remember right (I don't have Microsoft client installed on my computer at home, so I can't verify these commands right now):

"NET VIEW \\"  - list of domains
"NET VIEW /D:domain" - list of computers in a domain
"NET VIEW" - list of computers in your computer's domain

Not the best or most efficient way, but it should work.
0
 
watyCommented:
I had sources to do that, but I dont' find them. Will try to find.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mark2150Commented:
NET VIEW is the MSN / NT approach. Novell networks would require NDIR or some variant.
0
 
athakur999Commented:
I know you can map drives for any network (so long as the client conforms to Microsoft's requirements) using the NET command (ie., you can map Banyan drives with "NET USE K: \\StreetTalk\fs_blahblah@blah@blah").  I'd imagine the VIEW parameter would work as well...  I'll try when I go to work and see if it does.
0
 
jdyerCommented:
Use the EnumResources library function call

Download the file:

www.frogpond.com/~markg/examples/browse.zip

Implement the 32bit version. It is C code, but you should be able to follow it. Hope this helps.

Regards,
  jdyer
0
 
watyCommented:
I have found my project implementing in VB the retrieval of users, computers and user groups through the network.

As it is a zip file, give me your e-mail and I will send it to you or go to my web site, to download it.

waty.thierry@usa.net
http://www.geocities.com/ResearchTriangle/6311/

0
 
strongdAuthor Commented:
The link is bad.  He or she doesn't have a web page anymore.
0
 
jdyerCommented:
whose link?? Not mine, I just tried it the day I posted this to make sure!

Regards,
  jdyer
0
 
strongdAuthor Commented:
This link www.frogpond.com/~markg/examples/browse.zip does not work here.  I just tried it again.
0
 
jdyerCommented:
I tried it and it worked fine, tell me your e-mail and I will send it there.

OH CRAP! I'm sorry!

it should be www.frogpond.ORG

I AM VERY SORRY!!!

www.frogpond.org/~markg/examples/browse.zip

NOTE:

This program will only give a good hint as to what to do for very small networks... I can provide you with some C++ (MFC) code that will do it more efficiently for larger networks (it takes your computer, finds the workgroup name, and enumerates all the computers in the workgroup).

I am posting the function in the next comment, sorry it's in C++ - it should be fairly simple to translate to VB. If not you could compile it to a DLL and call it from there.

Regards,
jdyer
0
 
jdyerCommented:
This is heavily commented! Hopefully that will make it easier to understand. I have not actually tested this code (That's my job for tomorrow). I have used similar code, so this SHOULD work. If you would like a copy of my test program then I will send it to you to verify that the code works... HERE IT IS:


// --THIS SHOULD BE DECLARED IN winnetwk.h (but isn't)--
#ifdef __cplusplus
      extern "C" {
      #endif

      DWORD APIENTRY WNetGetResourceParentA(
        LPNETRESOURCE lpNetResource,
        LPVOID lpBuffer,
        LPDWORD lpBufferSize);

      DWORD APIENTRY WNetGetResourceParentW(
        LPNETRESOURCE lpNetResource,
        LPVOID lpBuffer,
        LPDWORD lpBufferSize);

      #ifdef UNICODE
      #define WNetGetResourceParent  WNetGetResourceParentW
      #else
      #define WNetGetResourceParent  WNetGetResourceParentA
      #endif // !UNICODE

      #ifdef __cplusplus
      }
      #endif
// ----------------------------------------------------


// Takes a listbox as an argument and fills the listbox
//  with all of the computers in the network, also sets
//  a global static (Label) control to the workgroup name
void CListNetCompsDlg::EnumerateComputers( CListBox& lst )
{
      LPNETRESOURCE lnpLocalComp;
      LPNETRESOURCE lnpWrkGrp;
      CString strCompName;
      char compName[500];
      char workGrp[500];
      DWORD compLen;
      HANDLE hEnum;

      DWORD dwEntries;
      DWORD dwResult;
      DWORD dwSize;

      dwEntries = 0xFFFFFFFF;                  // enumerate all possible
                                            //  entries

      dwSize = 16384;                        // should be plenty of
                                    //  room to fill array of
                                    //  resources

      compLen = sizeof( compName );


      // Try to allocate some resources, post a msg on error
      lnpLocalComp = (LPNETRESOURCE)GlobalAlloc( GPTR,                                    sizeof( LPNETRESOURCE ) );

      lnpWrkGrp = (LPNETRESOURCE)GlobalAlloc( GPTR,
                  sizeof( LPNETRESOURCE ) );

      if( (lnpLocalComp == NULL ) || (lnpWrkGrp == NULL ) )
      {
            MessageBox( "Global Memory Allocation failed!" );
            SendMessage( WM_CLOSE );
            return;
      }


      // get the computer name and prepend a "\\" to it
      //  For example if the computer name is MYPC it will now
      //  be \\MYPC (this is what a universal network name
      //  looks like)
      
              GetComputerName( compName, &compLen );
      strCompName.Format( "\\\\%s", compName );

      // fill the lpRemoteName variable of the NETRESOURCE
      //  structure with our computer name, we will use it to
      //  search up in the hierarchy for the workgroup name
      lnpLocalComp->lpRemoteName = (char*)
            ((LPCTSTR)strCompName);


      // Do the up-hierarchy search for the workgroup name
      compLen = sizeof( LPNETRESOURCE );
      dwResult = WNetGetResourceParent( lnpLocalComp,
            lnpWrkGrp,
            &compLen );

      if( dwResult != WN_SUCCESS )
      {
            MessageBox( "Error getting workgroup!" );
            SendMessage( WM_CLOSE );
            return;
      }

      // Remove the leading "\\" for display
      strcpy( workGrp, lnpWrkGrp->lpRemoteName + 2 );

      sWorkGroup.SetWindowText( workGrp );

      // Delete all current entries in listbox, otherwise
      //  if this is called onRefresh then it will display
      //  doubles
      lst.ResetContent();

      // Try to open a network resource enumeration and post
      //  a message on error
      dwResult = WNetOpenEnum( RESOURCE_GLOBALNET,
                        RESOURCETYPE_ANY,
                        0,
                        lnpWrkGrp,
                        &hEnum );
      
      if( dwResult != NO_ERROR )
      {
            MessageBox( "Could not open network enumeration!" );
            SendMessage( WM_CLOSE );
            return;
      }

      GlobalFree( lnpLocalComp );

      // make sure dwResult doesn't start out as
      //   ERROR_NO_MORE_ITEMS
      dwResult = ERROR_NO_MORE_ITEMS + 1;

      while( dwResult != ERROR_NO_MORE_ITEMS )
      {
            // Allocate resources
            lnpLocalComp = (LPNETRESOURCE)GlobalAlloc( GPTR,
                                          dwSize );


            // Try enumeration, fill list box with returned
            //  values, show message on error
            dwResult = WNetEnumResource( hEnum, &dwEntries,
                  lnpLocalComp, &dwSize );

            if( dwResult == NO_ERROR )
            {
                  CString strTrimmed;      // comp names w/o leading
                                    //  "\\"
                  
                  CString strNormal;            // CString representation
                                    //  of lpRemoteName

                  for( unsigned int i = 0; i < dwEntries; i++ )
                  {
                        strNormal = lnpLocalComp[i].lpRemoteName;

                                // Trim leading "\\" for display
                        strTrimmed = strNormal.Right(
                              strNormal.GetLength() - 2 );
                        
                        lst.AddString( strTrimmed );
                  }
            }
            else if( dwResult != ERROR_NO_MORE_ITEMS )
            {
                  MessageBox( "Enumeration Error!" );
                  SendMessage( WM_CLOSE );
                  return;
            }
      }

}      
0
 
strongdAuthor Commented:
Thanks for all your help.  I will go a head and compile it as a DLL and call it will VB.  This will help a whole lot!!!!   Thanks again jdyer.  
0
 
strongdAuthor Commented:
Thanks for all your help.  I will go a head and compile it as a DLL and call it will VB.  This will help a whole lot!!!!   Thanks again jdyer.  
0
 
jdyerCommented:
make sure to #include <winnetwk.h>

I'm not sure what your experience with C++ is...

you'll need to remove the

// Remove the leading "\\" for display
      strcpy( workGrp, lnpWrkGrp->lpRemoteName + 2 );

      sWorkGroup.SetWindowText( workGrp );

otherwise the dll call will fail (most probably) since it can't find sWorkGroup. If you need more help, let me know.

Regards,
  jdyer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now