How to check if the computer is connected to the network?

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

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

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

+6
source share
2 answers

Plain:

Ping ping = new Ping(); PingReply pingReply = ping.Send("ip address here"); if(pingReply.Status == IPStatus.Success) { //Machine is alive } 
+20
source

The best you can probably hope for without installing any user software on the target machine should be 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” computer is, and the status can only be detected locally, you will need to write a Windows service that will provide the WCF service. This service will be running on the target computer and will report local status at the request of the source computer.

+4
source

Source: https://habr.com/ru/post/917016/


All Articles