public static IPHostEntry GetHostEntry(string hostNameOrAddress)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(null, hostNameOrAddress);
NameResolutionPal.EnsureSocketsAreInitialized();
if (hostNameOrAddress == null)
{
throw new ArgumentNullException(nameof(hostNameOrAddress));
}
// See if it's an IP Address.
IPAddress address;
IPHostEntry ipHostEntry;
if (IPAddress.TryParse(hostNameOrAddress, out address))
{
if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
{
throw new ArgumentException(SR.Format(SR.net_invalid_ip_addr, nameof(hostNameOrAddress)));
}
ipHostEntry = InternalGetHostByAddress(address, true);
}
else
{
ipHostEntry = InternalGetHostByName(hostNameOrAddress, true);
}
if (NetEventSource.IsEnabled) NetEventSource.Exit(null, ipHostEntry);
return ipHostEntry;
}