Solved

Scanning Network to get computer names

Posted on 1998-08-17
15
312 Views
Last Modified: 2010-04-30
How do I scan a network to get computer names.  Not the users logged on.  Just computer names.  
0
Comment
Question by:strongd
  • 5
  • 4
  • 2
  • +3
15 Comments
 

Expert Comment

by:chitnis
ID: 1429363
use MAPI/ISAPI books.
0
 

Expert Comment

by:athakur999
ID: 1429364
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
 
LVL 14

Expert Comment

by:waty
ID: 1429365
I had sources to do that, but I dont' find them. Will try to find.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1429366
NET VIEW is the MSN / NT approach. Novell networks would require NDIR or some variant.
0
 

Expert Comment

by:athakur999
ID: 1429367
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
 
LVL 1

Expert Comment

by:jdyer
ID: 1429368
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
 
LVL 14

Expert Comment

by:waty
ID: 1429369
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:strongd
ID: 1429370
The link is bad.  He or she doesn't have a web page anymore.
0
 
LVL 1

Expert Comment

by:jdyer
ID: 1429371
whose link?? Not mine, I just tried it the day I posted this to make sure!

Regards,
  jdyer
0
 

Author Comment

by:strongd
ID: 1429372
This link www.frogpond.com/~markg/examples/browse.zip does not work here.  I just tried it again.
0
 
LVL 1

Accepted Solution

by:
jdyer earned 50 total points
ID: 1429373
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
 
LVL 1

Expert Comment

by:jdyer
ID: 1429374
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
 

Author Comment

by:strongd
ID: 1429375
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
 

Author Comment

by:strongd
ID: 1429376
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
 
LVL 1

Expert Comment

by:jdyer
ID: 1429377
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now