如何检查服务器是否还活着? [英] How to check a server is alive?

查看:187
本文介绍了如何检查服务器是否还活着?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不使用Ping()方法的情况下检查服务器是否处于活动状态。

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


推荐答案

如果是Active Directory服务器如您问题中标记的那样。您可以检查端口 389 3268

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

这篇关于如何检查服务器是否还活着?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆