Skip to content

Commit

Permalink
Always return IPv4 when pinging
Browse files Browse the repository at this point in the history
  • Loading branch information
hellzerg committed Jun 16, 2021
1 parent 2064fe8 commit 534f73f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Optimizer/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 534f73f

Please sign in to comment.