public static IPHostEntry Resolve(string hostName)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(null, hostName);
NameResolutionPal.EnsureSocketsAreInitialized();
if (hostName == null)
{
throw new ArgumentNullException(nameof(hostName));
}
// See if it's an IP Address.
IPAddress address;
IPHostEntry ipHostEntry;
if (IPAddress.TryParse(hostName, out address) && (address.AddressFamily != AddressFamily.InterNetworkV6 || SocketProtocolSupportPal.OSSupportsIPv6))
{
try
{
ipHostEntry = InternalGetHostByAddress(address, false);
}
catch (SocketException ex)
{
if (NetEventSource.IsEnabled) NetEventSource.Error(null, ex);
ipHostEntry = NameResolutionUtilities.GetUnresolvedAnswer(address);
}
}
else
{
ipHostEntry = InternalGetHostByName(hostName, false);
}
if (NetEventSource.IsEnabled) NetEventSource.Exit(null, ipHostEntry);
return ipHostEntry;
}