如何用程序实现PING?

解决方案 »

  1.   

    C# ping命令的实现方法:Ping类的使用
      

  2.   

    調用 cmd                ProcessStartInfo start = new ProcessStartInfo("CMD.exe");
                    start.Arguments = args;
                    //start.Arguments = @"/c ping "+ip;
                    start.CreateNoWindow = true;
                    start.RedirectStandardError = true;
                    start.RedirectStandardInput = true;
                    start.RedirectStandardOutput = true;
                    start.UseShellExecute = false;
                    Process p = Process.Start(start);
                    StreamReader sr = p.StandardError;
                    string str = sr.ReadToEnd();
                    p.WaitForExit();
                    p.Close();
                    sr.Close();
                    if (!string.IsNullOrEmpty(str))
                    {
                        throw new Exception("RunAsCmd Fail!\r\nArgs:" + args + "\r\nError:\r\n" + str);
                    }