简体   繁体   中英

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.

Simple:

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM