SamKr
10/24/2018 - 9:41 AM

Get IP

Tries to get the local IP, change the 192 value for different subnets

var host = Dns.GetHostEntry(Dns.GetHostName());

foreach (var ip in host.AddressList)
{
    var localIp = ip.ToString();
    var temp = localIp.Split('.');
    switch (ip.AddressFamily)
    {
        case AddressFamily.InterNetwork when temp[0] == "192":
            return localIp;
    }
}

return "127.0.0.1";