C# 判断ip地址能否被ping通
string ip = "127.0.0.1"; //要检查的IP地址 Ping pingSender = new Ping(); try { PingReply reply = pingSender.Send(ip, 120); if (reply.Status == IPStatus.Success) { Console.WriteLine($"Ping {ip} 成功。"); } else { Console.WriteLine($"Ping {ip} 失败:{reply.Status}."); } } catch (PingException ex) { Console.WriteLine(ex.ToString()); }