Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Scanning Network to get computer names

Posted on 1998-08-17
15
Medium Priority
?
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 

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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

715 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