📜  获取当前计算机 ipv4 C# 代码示例

📅  最后修改于: 2022-03-11 14:49:10.935000             🧑  作者: Mango

代码示例1
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!");
}