I'm trying to get the IPv4 string of ipconfig cmd using c# for consuming API on IIS server. I'm using this code
public static string GetLocalIPAddress()
{
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
throw new Exception("No network adapters with an IPv4 address in the system!");
}
but the Ip I get from it is different from the one in ipconfig cmd. How can I get the exact IPv4 from ipconfig cmd using C#?