using System.Net;
/// <summary>
/// Parses an IP string, and verifies that it is in the HostEntry's AddressList.
/// </summary>
/// <param name="localIPString">The string to parse and verify</param>
/// <returns><paramref name="localIPString"/>, if it is a valid local IP and found in the HostName's AddressList; otherwise, <see cref="IPAddress.Any"/></returns>
public static IPAddress TryLocalIPOrAny(string localIPString)
if (localIPString != null && IPAddress.TryParse(localIPString, out IPAddress address))
if (Dns.GetHostEntry(Dns.GetHostName()).AddressList.Contains(address))
return address;