Skip to content

Commit

Permalink
Fix 'System.PlatformNotSupportedException: The system's ping utility …
Browse files Browse the repository at this point in the history
…could not be found.' (#702)
  • Loading branch information
ColdeZhang authored Dec 4, 2024
1 parent 22d6b79 commit d9630a7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Lagrange.Core/Utility/Network/Icmp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ internal static class Icmp
{
public static async Task<long> 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;
}
}
}

0 comments on commit d9630a7

Please sign in to comment.