private StringCollection GetIps()
{
StringCollection Ips= new StringCollection();
ProcessStartInfo calistir = new ProcessStartInfo("net", "view");
calistir.CreateNoWindow = true;
calistir.UseShellExecute = false;
calistir.RedirectStandardOutput = true;
Process calistirbasla = Process.Start(calistir);
StreamReader oku = calistirbasla.StandardOutput;
StringCollection isimler = MakineIsimleri(oku.ReadToEnd());
foreach (string machine in isimler)
{
Ips.Add(IPAddresses(machine));
}
return Ips;
}
You can get hostnames with :
StringCollection isimler = MakineIsimleri(oku.ReadToEnd());
private StringCollection MakineIsimleri(string CalistirCiktisi)
{
string hepsi = CalistirCiktisi.Substring(CalistirCiktisi.IndexOf("\\"));
StringCollection makineler = new StringCollection();
while (hepsi.IndexOf("\\") != -1)
{
makineler.Add(hepsi.Substring(hepsi.IndexOf("\\"),
hepsi.IndexOf(" ", hepsi.IndexOf("\\")) - hepsi.IndexOf("\\")).Replace("\\", String.Empty));
hepsi = hepsi.Substring(hepsi.IndexOf(" ", hepsi.IndexOf("\\") + 1));
}
return makineler;
}
And :
private string IPAddresses(string server)
{
try
{
IPHostEntry heserver = Dns.Resolve(server);
return heserver.AddressList[0].ToString();
}
catch(SocketException ex)
{
return MessageBox.Show(ex.Message+" Şu Serverda : "+server).ToString();
}
}