透過 `System.Diagnostics.Process` 啟動隱藏的 `cmd.exe`,注入 `ping` 命令並捕獲標準輸出流分析結果。
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine($"ping -n 1 {targetIp}");
p.StandardInput.WriteLine("exit");
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
// 解析 output 判斷連通性、延遲、丟包率等
.NET Core / .NET 5+ 推薦使用 `System.Net.NetworkInformation.Ping` 類,原生、跨平台、高效能。