public static string GetLocalIp()
{
    string hostname = Dns.GetHostName();
    IPHostEntry localhost = Dns.GetHostEntry(hostname);
    if (localhost != null)
    {
        foreach (IPAddress item in localhost.AddressList)
        {
            //判断是否是内网IPv4地址
            if (item.AddressFamily == AddressFamily.InterNetwork)
            {
                return item.MapToIPv4().ToString();
            }
        }
    }
    return "127.0.0.1";
}

 

 

  

相关文章:

  • 2022-12-23
  • 2022-02-18
  • 2021-10-21
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-05
  • 2021-07-05
  • 2022-12-23
  • 2021-09-25
  • 2021-09-03
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案