How can I know which machines are alive on the same LAN as my PC using ASP.NET?
You can ping the computers on the network.
// addressToPing can be an IPaddress or host name.
// returns a boolean indicating successful ping
public static bool PingComputer (string[] addressToPing)
{
Ping pingSender = new Ping ();
PingOptions options = new PingOptions ();
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes (data);
int timeout = 120;
PingReply reply = pingSender.Send (args[0], timeout, buffer, options);
return reply.Status == IPStatus.Success;
}
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx
You can use this ping code and iterate through the IP addresses on your LAN (for(i = 1; i < 255; i++)
). You should probably read up on doing IP address calculations though:
This is called a 'ping sweep'. It does assume that the computers on the network have not been configured to ignore ICMP requests.
I would approach this in two parts; an ASP.NET page and an always-running service.
The always running service an monitor for ARP requests to get a good idea of which machines are active. In order to see ARP replies it will have to issue its own ARP requests. On Windows networks there is always enough idle traffic (for browse computers) to get a very good idea of which machines are active.
If you have the ability to install monitoring software on the various computers on the network, I've had good luck using nagios for tracking which servers are up/under heavy load/out of disk space/etc in a production network. It also has a nice web front end that you wouldn't even need to use ASP for at all.
If you must create something home-grown with ASP, I would use nmap to scan your class C subnet and then print the results in your ASP page. This isn't a very efficient method, but it would be very simple and be pretty much guaranteed to work (with appropriate options).