private Boolean Ping()
{
 PingOptions options = new PingOptions();
 options.DontFragment = true;
 options.Ttl = 128;

 string _32Chars = "12345678123456781234567812345678";
 byte[] _32BytesBuf = Encoding.ASCII.GetBytes(_32Chars);

 PingReply reply = null;
 try
 {
  Ping pingSender = new Ping();
  reply = pingSender.Send(strAddress, nTimeOut, _32BytesBuf, options);
 }
 catch (Exception ex)
 {
  Debug.WriteLine("[" + ex.Message + "]");
  return false;
 }

 return reply.Status == IPStatus.Success;
}

 


本文链接地址: C#中Ping类的使用
http://qingfengju.com/index.asp?id=306

分类:Win32/C++ 查看次数:4704 发布时间:2011-12-19 0:53:34