In the internet there are several places that show you how to get an IP address. And a lot of them look like this example:
String strHostName = string.Empty;
This returns addresses from any interfaces that have gateway addresses and unicast addresses in two separate lists, IPV4 and IPV6.
public static (List V4, List V6) GetLocal()
{
List foundV4 = new List();
List foundV6 = new List();
NetworkInterface.GetAllNetworkInterfaces().ToList().ForEach(ni =>
{
if (ni.GetIPProperties().GatewayAddresses.FirstOrDefault() != null)
{
ni.GetIPProperties().UnicastAddresses.ToList().ForEach(ua =>
{
if (ua.Address.AddressFamily == AddressFamily.InterNetwork) foundV4.Add(ua.Address);
if (ua.Address.AddressFamily == AddressFamily.InterNetworkV6) foundV6.Add(ua.Address);
});
}
});
return (foundV4.Distinct().ToList(), foundV6.Distinct().ToList());
}