From d9630a7551bc982d8d3fcda83a6c877e5604240a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=AE=87=E8=A1=A1?= Date: Wed, 4 Dec 2024 15:16:25 +0800 Subject: [PATCH] Fix 'System.PlatformNotSupportedException: The system's ping utility could not be found.' (#702) --- Lagrange.Core/Utility/Network/Icmp.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Lagrange.Core/Utility/Network/Icmp.cs b/Lagrange.Core/Utility/Network/Icmp.cs index 4bf2701a6..a8d17ded5 100644 --- a/Lagrange.Core/Utility/Network/Icmp.cs +++ b/Lagrange.Core/Utility/Network/Icmp.cs @@ -6,8 +6,15 @@ internal static class Icmp { public static async Task PingAsync(Uri hostIp, int timeout = 1000) { - using var ping = new Ping(); - var reply = await ping.SendPingAsync(hostIp.Host, timeout); - return reply?.RoundtripTime ?? long.MaxValue; + try + { + using var ping = new Ping(); + var reply = await ping.SendPingAsync(hostIp.Host, timeout); + return reply?.RoundtripTime ?? long.MaxValue; + } + catch (PlatformNotSupportedException) + { + return long.MaxValue; + } } } \ No newline at end of file