首页 > 代码库 > C# 后台 用ping 来判断网络是否正常

C# 后台 用ping 来判断网络是否正常

              System.Diagnostics.Process  proIP=new  System.Diagnostics.Process();               proIP.StartInfo.FileName="cmd.exe";               proIP.StartInfo.UseShellExecute  =  false;               proIP.StartInfo.RedirectStandardInput  =  true;               proIP.StartInfo.RedirectStandardOutput  =  true;               proIP.StartInfo.RedirectStandardError  =  true;               proIP.StartInfo.CreateNoWindow  =  true;// 不显示 cmd 窗口                proIP.Start();               proIP.StandardInput.WriteLine("ping   www.baidu.com");               proIP.StandardInput.WriteLine("exit");               string  strResult=proIP.StandardOutput.ReadToEnd();              if (strResult.IndexOf("(0% 丢失)") != -1 || strResult.IndexOf("(0% loss)") != -1)                  Response.Write("<script>alert(‘Ping  通了!‘)</script>");               else if (strResult.IndexOf("(100% 丢失)") != -1 || strResult.IndexOf("(100% loss)") != -1)                  Response.Write("<script>alert(‘ 无法   Ping  通!‘)</script>");               else                 Response.Write("<script>alert(‘数据有丢失!‘)</script>");                  proIP.Close();

 

 

C# 后台 用ping 来判断网络是否正常