|
Written by Praveen V Nair
|
|
Apr 30, 2007 at 05:16 AM |
|
Author: PraVeeN - Microsoft MVP
LanScan is a utility for cheking which computer is ON and which computer is
OFF now.
This application is developed with Dotnet 2.0 with C# .
Well..., this is the heart code:
private void ThreadProc()
{
pictureBox1.Visible =
true;
button1.Enabled =
false;
label1.Visible =
true;
Ping p = new Ping();
PingReply pr = null;
System.Net.IPAddress ipaddress = null;
string hostname = string.Empty;
for (int i = 1; i < 255;
i++)
{
label1.Text = "Checking
" + i.ToString() + "/255
Machines";
Application.DoEvents();
ipaddress =
System.Net.IPAddress.Parse("192.168.0."
+ i.ToString());
pr = p.Send(ipaddress, 1);
if (pr.Status.ToString() == "Success")
{
hostname =
System.Net.Dns.GetHostByAddress(ipaddress).HostName.ToString();
ListViewItem lv =
listView1.Items.Add(ipaddress.ToString());
lv.SubItems.Add(hostname);
lv.SubItems.Add("On");
lv.ForeColor = Color.DarkGreen;
lv =
listView2.Items.Add(ipaddress.ToString());
lv.SubItems.Add(hostname);
lv.SubItems.Add("On");
lv.ForeColor = Color.DarkGreen;
}
else
{
ListViewItem lv =
listView1.Items.Add(ipaddress.ToString());
lv.SubItems.Add("");
lv.SubItems.Add("Off");
lv.ForeColor = Color.Red;
lv =
listView3.Items.Add(ipaddress.ToString());
lv.SubItems.Add("");
lv.SubItems.Add("Off");
lv.ForeColor = Color.Red;
}
label2.Text =
"Total " +
listView2.Items.Count + " Machines
ON";
}
label1.Visible = false;
button1.Enabled = true;
pictureBox1.Visible =
false;
}
Download Executable
Download Source
|