Click here to Skip to main content
15,922,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get the all computers IP address list connected to network in C#
Posted
Updated 6-May-11 1:32am
v2

If all connected to windows server - LDAP, we can get that information. Hope it solves.
 
Share this answer
 
Of many articles on LAN network here at CP itself, this one should meet your needs: A collection class for listing all the computers and servers in your network, with category information[^]

Please use CP articles repository, it has great many articles. A simple search can provide you much more in case you need.

Similar questions asked earlier and answered: get ipp address of all pcs connected via lan [^]
 
Share this answer
 
Comments
Ed Nutting 6-May-11 15:28pm    
Good answer (and advice), my 5 :)
Sandeep Mewara 6-May-11 23:09pm    
Thanks.
0) I found this code on msdn, but if you're on a corporate/military network, you may not be able to get the desired output:

C#
using System.Diagnostics;  
using System.IO;  
  
//Gets the machine names that are connected on LAN  
Process netUtility = new Process();  
netUtility.StartInfo.FileName = "net.exe";  
netUtility.StartInfo.CreateNoWindow = true;  
netUtility.StartInfo.Arguments = "view";  
netUtility.StartInfo.RedirectStandardOutput = true;  
netUtility.StartInfo.UseShellExecute = false;  
netUtility.StartInfo.RedirectStandardError = true;  
netUtility.Start();  
  
StreamReader streamReader = new StreamReader(netUtility.StandardOutput.BaseStream, netUtility.StandardOutput.CurrentEncoding);  
  
string line = "";  
  
while ((line = streamReader.ReadLine()) != null)  
{  
      if (line.StartsWith("\\"))  
      {  
           listBox1.Items.Add(line.Substring(2).Substring(0, line.Substring(2).IndexOf(" ")).ToUpper());  
      }  
}  
  
streamReader.Close();  
netUtility.WaitForExit(1000);  


1) You could do a ping sweep, but that would take forever, and if the Windows firewall is enabled on any of the boxes, it may be configured to refuse ICMP requests, and you're stuck - again.

2) Insteat of using net.exe in the first example, you could use nMap.exe. Google for the commandline parameters.
 
Share this answer
 
Comments
yesotaso 6-May-11 10:11am    
I did something like this in the company I work a few minutes later I got phone from IT "Did you install some malware?" obviously corporate sercurity program may take it as network attack :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900