2011-02-16 116 views

回答

3

使用Ping class

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

您可以在您的Global.asax启动定时器,并通过使用Ping类

+0

它不是Global.aspx它的Global.asax – 2011-02-16 08:27:50

+0

哎呀,固定@Shekhar_Pro,谢谢 – 2011-02-16 08:29:20

1

有一个PING类,你可以使用在每一个时间间隔平你的域。您可以使用发送方法来执行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); 
     } 
相关问题