From 534f73f5a77416e5f03012c661054237295ece6f Mon Sep 17 00:00:00 2001 From: deadmoon Date: Wed, 16 Jun 2021 16:20:26 +0300 Subject: [PATCH] Always return IPv4 when pinging --- Optimizer/Utilities.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Optimizer/Utilities.cs b/Optimizer/Utilities.cs index bcdd1c1d..136ed5ba 100644 --- a/Optimizer/Utilities.cs +++ b/Optimizer/Utilities.cs @@ -8,6 +8,7 @@ using System.Management.Automation; using System.Net; using System.Net.NetworkInformation; +using System.Net.Sockets; using System.Reflection; using System.Security.Principal; using System.ServiceProcess; @@ -35,6 +36,8 @@ internal static class Utilities internal static Ping pinger = new Ping(); + static IPAddress addressToPing; + internal delegate void SetControlPropertyThreadSafeDelegate(Control control, string propertyName, object propertyValue); internal static void SetControlPropertyThreadSafe(Control control, string propertyName, object propertyValue) @@ -633,7 +636,10 @@ internal static PingReply PingHost(string nameOrAddress) PingReply reply; try { - reply = pinger.Send(nameOrAddress); + addressToPing = Dns.GetHostAddresses(nameOrAddress) + .First(address => address.AddressFamily == AddressFamily.InterNetwork); + + reply = pinger.Send(addressToPing); return reply; } catch