/// <summary> /// 网络测试 /// </summary> private void TestNet( ) { //远程服务器IP string ipStr = "192.168.0.8"; //构造Ping实例 Ping pingSender = new Ping(); //Ping 选项设置 PingOptions options = new PingOptions(); options.DontFragment = true; //测试数据 string data = ""; byte[] buffer = Encoding.ASCII.GetBytes(data); //设置超时时间 int timeout = 120; //调用同步 send 方法发送数据,将返回结果保存至PingReply实例 PingReply reply = pingSender.Send(ipStr, timeout, buffer, options); string lst_PingResult = string.Empty; if (reply.Status == IPStatus.Success) { lst_PingResult = lst_PingResult+ ("答复的主机地址:" + reply.Address.ToString())+" "; lst_PingResult = lst_PingResult + ("往返时间:" + reply.RoundtripTime) + " "; lst_PingResult = lst_PingResult + ("生存时间(TTL):" + reply.Options.Ttl) + " "; lst_PingResult = lst_PingResult + ("是否控制数据包的分段:" + reply.Options.DontFragment) + " "; lst_PingResult = lst_PingResult + ("缓冲区大小:" + reply.Buffer.Length) + " "; }; }