pharaon450
pharaon450

Reputation: 523

How can I check if a computer on my network is online?

I want to know how to check if a machine on my network is online, using only C#.

All machines on my network use the same OS (Windows 7) and I'm logged in as the same user on all machines.

My goal is to check if they are active, or open.

Upvotes: 11

Views: 22935

Answers (2)

Nate
Nate

Reputation: 30646

The best you can probably hope for without installing some custom software on the target machine is to use the Ping class.

A quick and dirty implementation might look like this:

var p = new Ping();
if(p.Send("HostNameOrIP").Status != Success) return;

If you have very specific requirements about what an "active and open" machine is, and the state can only be detected locally, you will need to write a windows service that will expose a WCF service. This service will run on the target computer and report back the local status when requested by the source computer.

Upvotes: 6

dtsg
dtsg

Reputation: 4459

Simple:

Ping ping = new Ping();
PingReply pingReply = ping.Send("ip address here");

if(pingReply.Status == IPStatus.Success)
{
   //Machine is alive
}

Upvotes: 25

Related Questions