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:
using System.Diagnostics;
using System.IO;
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.