How to check a server is alive? [duplicate]

烂漫一生 提交于 2020-01-05 13:13:12

问题


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;
    }

回答1:


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 ; 
    }
}


来源:https://stackoverflow.com/questions/24525797/how-to-check-a-server-is-alive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!