Thursday 9 May 2013

Get List of computers connected in LAN


using System.Net.NetworkInformation;

List<string> IP = new List<string>();
private void button1_Click(object sender, EventArgs e)
{
   Ping obj = new Ping();
   for (int i = 0; i < 255; i++)
   {
     try
     {
      PingReply objreply = obj.Send("192.168.0." + i.ToString());
      if (objreply.Status != IPStatus.DestinationHostUnreachable)
       {
          IP.Add(objreply.Address.ToString());
          IP.Add(Dns.GetHostByAddress(objreply.Address).HostName);
       }
     }
     catch
     {
     }
   }           
   ListBox.DataSource = IP;
}


 

No comments:

Post a Comment