Click here to Skip to main content
Click here to Skip to main content

List Peer Servers and their IP Addresses inside a Workgroup.

, 26 Aug 2002
Rate this:
Please Sign up or sign in to vote.
How to list the peer servers and IP addresses in the workgroup - A simple approach.

Sample Image - PeerLister.jpg

Introduction

How can peer servers inside a work group be listed. I wanted to demonstrate a simple method to perform this operation. System.Remoting namespace provides certain APIs using which this can be performed. At CodeProject, I saw a couple of articles performing similar operations in MC++ and they printout the IP addresses too.

The articles are available at these links:

Overview

I chose to use the Shell basics. Using Shell basics, several tasks can be done very simply. The Shell32 DLL is interoped with the project and it exposes a number of methods, classes and interfaces to perform a lot of operations, like using the Windows UI.

The Shell organizes these objects into a hierarchical structure called the namespace, which provides users and applications with a consistent and efficient way to access and manage objects. Users interact with the namespace through the Shell's graphical UI or through an application. Applications interact with the namespace through the Shell's application programming interface (API). This section is an introduction to the Shell API.

There are plenty of objects used to create applications and manage the operating system. The most familiar of these objects are the folders and files that reside on computer disk drives and over networks.

Some of the basics ,how-tos and the APIs used will be explained in this article.

The platform considered is Windows 2000 Server and such a server present under a workgroup server. The requirement is to view the peer servers under the workgroup. Shell basics are used to perform the above said task.

Some Preliminaries

The workgroup when opened using an Explorer, displays the servers that are present in it. One has to understand the differences between:

  1. Folder
  2. NameSpace
  3. FolderItem
  4. Link, etc.

An object of type Shell32.Shell is created and another object of type Shell32.Folder is also created. There are some special folders specified. Such as ShellSpecialFolderConstants.ssfNETWORK represents the Network Places folder. My Documents, Control Panel and several special folders are defined and are identified by separate constants.

The folder is parsed only when isFileSystem return false. The link is opened by using Shell.NameSpace(object) and iterated until the workgroup server folder is reached.

Once the namespace is known, the items() gives a collection, from which an individual item can be retrieved. The code is given below:

Shell32.Shell sh = new Shell32.Shell();
Shell32.Folder currFolder = 
  sh.NameSpace(Shell32.ShellSpecialFolderConstants.ssfNETWORK);
int num = 
  sh.NameSpace(Shell32.ShellSpecialFolderConstants.ssfNETWORK).Items().Count;
MessageBox.Show("The Num of Items in special folder in the local",
  currFolder.Items().Count.ToString());
					
for(int i=0;i<num;i++)
{

 if(currFolder.Items().Item(i).IsFileSystem==false)
 {
  if(currFolder.Items().Item(i).Type.ToString()=="")
  {
   MessageBox.Show(currFolder.Items().Item(i).Name);
   int no =sh.NameSpace(currFolder.Items().Item(i)).Items().Count;
   currFolder = sh.NameSpace(currFolder.Items().Item(i));
   MessageBox.Show(no.ToString());

   MessageBox.Show(currFolder.Items().Item(0).Name+": Cool");
   currFolder=
    sh.NameSpace(sh.NameSpace(currFolder.Items().Item(0)).Items().Item(0));
   MessageBox.Show(currFolder.Items().Count+": Count");

   MessageBox.Show(mycount.ToString());
						
   for(int k=1;k<mycount;k++)
   {
    try
    {

     listView1.Items.Add(new ListViewItem
      (currFolder.Items().Item(k).Name+k.ToString()));

    }
    catch(Exception myexcep)
    {
								
     MessageBox.Show(myexcep.ToString()+" : Error");

    }
   }
  }
 }
}

Update

There is a very simple method to find the IP address of the servers under the workgroup server. These are found in the System.Net namespace. The peer servers are added in to a ListView control as listviewItem. The Net Namespace contains a plethora of classes and APIs for network access. The IP address can be found by passing the domain name of the server.

Sample Image - IP Address.jpg

The giveAddress method returns the IP address of the Server.

this.listView1.DoubleClick += new System.EventHandler(this.giveAddress);

The following is an example of how it is done....

private void giveAddress(object sender, System.EventArgs e)
{
 MessageBox.Show(System.Net.Dns.Resolve(listView1.FocusedItem.Text).
 AddressList.GetValue(0).ToString());
}

The MessageBox displays the IP address of the selected server.

Conclusion

This is an illustration of the use of the Shell basics and a method for how the peers in a workgroup are listed and the IP addresses of the servers found.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Ragavendran Vaidhyanadhan
Web Developer
United States United States
Ragavendran was born in South India. He holds a Bacnelor of Computer Science and Engineering. Currently he works as a Software Engineer. He is techno Savvy and All he wishes to do in life is to get to know a lotta things....
He is always intrigued about learning new things.
 
His skills include C,C++,Java ,.NET.He also experience working in Legacy Systems. He feels most comfortable with C++ and Java.
Computers are his first love and he likes reading books, music and trekking.
 
He is a voracious reader and loves reading books. A Leo by birth, he loves trekking and gardening. One of his main ambitions is to write his autobiography, though he is not sure who will read it.

Comments and Discussions

 
Generalerrors PinsussAnonymous2-Nov-02 9:13 
GeneralRe: errors PinmemberRagavendran Vaidhyanadhan1-Apr-03 3:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411028.1 | Last Updated 27 Aug 2002
Article Copyright 2002 by Ragavendran Vaidhyanadhan
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid