C# Check Remote Server

.net, c#

Solution

You could ping it

You could download the default page from it

You could do a HEAD request

If it's a local IIS6 server on your network, and you have some admin details, you could connect to IIS using some DirectoryEntry code

Some of the answers on 136615 might help too, specifically the accepted answer that talks about sockets

For the print servers (or, specifically, the printers), the code by K Scott here might help. It's fun code to play with anyway :-) That code mentions dns.resolve, which is obsoleted and replaced by Dns.GetHostEntry

I'm about out of ideas :-)

Problem

Can anyone advise what the best way to check (using .NET 3.5) if a remote server is available? I was thinking of using the following code but would like to know if a better way exists if the community has another option. ``` TcpClient client = new TcpClient("MyServer", 80); if (!client.Connected) { throw new Exception("Unable to connect to MyServer on Port 80"); } client.Close(); ```

Original source

Related problems