如何使用C#.net每隔几秒/分钟ping一次域?

如何使用C#.net每隔几秒/分钟ping一次域?,c#,asp.net,dns,httpresponse,ping,C#,Asp.net,Dns,Httpresponse,Ping,我打算开发一个网站,在每一个时间间隔ping域名,以检查域名状态。参考网站:这个网站也喜欢做同样的事情。如何使用C#获取Ping统计信息?使用 您可以在Global.asax中启动计时器,并使用ping类在每个时间间隔ping您的域。有一个类您可以使用。您可以使用Send方法执行ping并接收回波 Ping pingSender = new Ping (); PingOptions options = new PingOptions (); //

我打算开发一个网站,在每一个时间间隔ping域名,以检查域名状态。参考网站:这个网站也喜欢做同样的事情。如何使用C#获取Ping统计信息?

使用

您可以在Global.asax中启动计时器,并使用ping类在每个时间间隔ping您的域。有一个类您可以使用。您可以使用Send方法执行ping并接收回波

        Ping pingSender = new Ping ();
        PingOptions options = new PingOptions ();

        // Use the default Ttl value which is 128,
        // but change the fragmentation behavior.
        options.DontFragment = true;

        // Create a buffer of 32 bytes of data to be transmitted.
        string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        byte[] buffer = Encoding.ASCII.GetBytes (data);
        int timeout = 120;
        PingReply reply = pingSender.Send (args[0], timeout, buffer, options);
        if (reply.Status == IPStatus.Success)
        {
            Console.WriteLine ("Address: {0}", reply.Address.ToString ());
            Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
            Console.WriteLine ("Time to live: {0}", reply.Options.Ttl);
            Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment);
            Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length);
        }

It not Global.aspx its Global.asaxOops,修复了@Shekhar_Pro,谢谢你hanks@Shekhar_Pro,+1你也一样;)你是做工作还是做私人生意?@ArsenMkrt你的工作在哪里?很高兴认识你。
        Ping pingSender = new Ping ();
        PingOptions options = new PingOptions ();

        // Use the default Ttl value which is 128,
        // but change the fragmentation behavior.
        options.DontFragment = true;

        // Create a buffer of 32 bytes of data to be transmitted.
        string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        byte[] buffer = Encoding.ASCII.GetBytes (data);
        int timeout = 120;
        PingReply reply = pingSender.Send (args[0], timeout, buffer, options);
        if (reply.Status == IPStatus.Success)
        {
            Console.WriteLine ("Address: {0}", reply.Address.ToString ());
            Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
            Console.WriteLine ("Time to live: {0}", reply.Options.Ttl);
            Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment);
            Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length);
        }