2
我去开发网站,每隔一定的时间间隔ping域来检查域的状态。参考网站:http://pingdom.com/这个网站也喜欢做同样的事情。我如何使用C#获得Ping统计信息..?如何使用C#.net每隔几秒钟/分钟ping域?
我去开发网站,每隔一定的时间间隔ping域来检查域的状态。参考网站:http://pingdom.com/这个网站也喜欢做同样的事情。我如何使用C#获得Ping统计信息..?如何使用C#.net每隔几秒钟/分钟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);
}
您可以在您的Global.asax启动定时器,并通过使用Ping类
有一个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);
}
它不是Global.aspx它的Global.asax – 2011-02-16 08:27:50
哎呀,固定@Shekhar_Pro,谢谢 – 2011-02-16 08:29:20