1

I want to check a server if it is alive or not without using Ping() method.

Are there any solutions to to that?

At the current the method below is ok to me.

public static bool PingToServer(string ipServer)
    {
        bool isServerLife = false;
        try
        {
            Ping ping = new Ping();
            PingReply pingReply = ping.Send(ipServer, 5000);

            if (pingReply.Status == IPStatus.Success)
            {
                isServerLife = true;
            }
        }
        catch (Exception e)
        {
            Console.Write("PingToServer: Cannot ping to server, " + e.Message);
        }
        return isServerLife;
    }
NoName
  • 877
  • 12
  • 28

1 Answers1

2

If it's an Active Directory Server as tagged in your question. You can check port 389 or 3268.

public static bool IsADSAlive(String hostName) 
{
    try {
        using (TcpClient tcpClient = new TcpClient()) 
        {
           tcpClient.Connect(hostName, 3268);
           return true; 
        } 
    }  catch (SocketException) { 

      return false ; 
    }
}
Perfect28
  • 11,089
  • 3
  • 25
  • 45