What is the easiest way to check if a computer is alive and responding (say in ping/NetBios)? I'd like a deterministic method that I can time-limit.
One solution is simple access the share (File.GetDirectories(@"\compname")) in a separate thread, and kill the thread if it takes too long.
To check a specific TCP port (myPort
) on a known server, use the following snippet. You can catch the System.Net.Sockets.SocketException
exception to indicate non available port.
using System.Net;
using System.Net.Sockets;
...
IPHostEntry myHostEntry = Dns.GetHostByName("myserver");
IPEndPoint host = new IPEndPoint(myHostEntry.AddressList[0], myPort);
Socket s = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
s.Connect(host);
Further, specialized, checks can try IO with timeouts on the socket.
Easy! Use System.Net.NetworkInformation
namespace's ping facility!
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With