Click here to Skip to main content
13,504,308 members
Click here to Skip to main content
Add your own
alternative version


25 bookmarked
Posted 6 May 2004

Enumerate All of the IP Addresses on the Network W/O ActiveDirectory

, 6 May 2004
Rate this:
Please Sign up or sign in to vote.
This will enumerate all of the IP Addresses on the network without using ActiveDirectory.


This code gets all of the IP addresses on the network. The best part is, it doesn't use ActiveDirectory. It uses the default DOS commands for networking, specifically "net view". Also, it uses the System.Net.Dns class to resolve the IPs.


private ArrayList GetIPAddresses()
 ArrayList Addresses = new ArrayList(); // Temp array to fill
 //Get my address
 string MyAdd = 
 // Used to start the command
 System.Diagnostics.ProcessStartInfo psi = 
       new System.Diagnostics.ProcessStartInfo();
 psi.FileName = @"C:\WINDOWS\system32\cmd.exe"; // Path for the cmd prompt
 psi.Arguments = "/c net view > boo.txt"; // Arguments for the command prompt
 // "/c" tells it to run the following command which is "net view > boo.txt"
 // "net view" lists all the computers on the network
 // " > boo.txt" tells dos to put the results in a file called boo.txt
 psi.WindowStyle = 
  System.Diagnostics.ProcessWindowStyle.Hidden; // Hide the window
 // So the computer doesn't bog down
 System.Diagnostics.Process.Start(psi); // Run
 System.IO.StreamReader sr = null; // used for boo.txt
 bool run = false; // used to tell if dos is done yet
 while(run == false) // while dos is still running
  Application.DoEvents(); // let windows do it's stuff
   System.Threading.Thread.Sleep(1000); // wait a second
   sr = new System.IO.StreamReader(Application.StartupPath 
                   + "\\boo.txt"); // Try to open the file
   // If dos is not done yet, this will throw an error
   run = true; // If I get here, dos is done and we can use the file
   run = false; // Dos is not done yet
 // Cycle through the file until the info starts
 while(sr.ReadLine().StartsWith("--") != true) 
 string str = ""; // filled with each line of the file
 string[] comp = new string[32]; // temp array of computer names
 int i = 0; // indexer for comp[]
 // cycle until we reach, "The command completed successfully."
 while(str.StartsWith("The") != true) 
   str = sr.ReadLine(); // Read the next line
  // Split the line after the first space
   comp[i] = str.Split(char.Parse(" "))[0];
   // Normally, in the file it lists it like this
   // \\MyComputer                 My Computer's Description

  // Take off the slashes, "\\MyComputer" to "MyComputer"
   comp[i] = comp[i].Substring(2, comp[i].Length - 2);
   if(comp[i] == "e") 
  // For some reason, I was getting an element
  // in this array that has the value of "e", so I took 
  // it out! lol
     comp[i] = null;
   i++; // move to the next place in comp[]
 sr.Close(); // close the file handle
 sr = null; // free memory
 foreach(string s in comp) // for every computer that we have...
  if(s != null) // if there really is a computer...
   if(s.ToUpper() != Dns.GetHostName().ToUpper()) 
  // if the computer is not me...
  // ... add the address to the array
 return Addresses; // return the array

All you have to do is call this function. E.g.:

ArrayList Adds = new ArrayList();
Adds = GetIPAddresses();


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


About the Author

United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
Member 654289910-Sep-09 15:21
memberMember 654289910-Sep-09 15:21 
GeneralMy vote of 1 Pin
legion_9-Jul-09 11:38
memberlegion_9-Jul-09 11:38 
GeneralSuggestion Pin
James Thresher9-May-04 20:16
memberJames Thresher9-May-04 20:16 
GeneralRe: Suggestion Pin
MichaelCoder11-May-04 12:55
memberMichaelCoder11-May-04 12:55 
GeneralRe: Suggestion Pin
James Thresher11-May-04 19:35
memberJames Thresher11-May-04 19:35 
GeneralRe: Suggestion Pin
MichaelCoder12-May-04 9:43
memberMichaelCoder12-May-04 9:43 
GeneralRe: Suggestion Pin
James Thresher12-May-04 21:07
memberJames Thresher12-May-04 21:07 
GeneralRe: Suggestion Pin
mdsicignano12-Sep-07 5:00
membermdsicignano12-Sep-07 5:00 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180417.1 | Last Updated 7 May 2004
Article Copyright 2004 by MichaelCoder
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid