unity 获取本机ip地址

IPAddress[] ips = Dns.GetHostAddresses(Dns.GetHostName());   //Dns.GetHostName()获取本机名Dns.GetHostAddresses()根据本机名获取ip地址组
foreach (IPAddress ip in ips)
{
  if (ip.AddressFamily == AddressFamily.InterNetwork)
  {
    ip4 = ip.ToString();  //ipv4

  }

  else if(ip.AddressFamily == AddressFamily.InterNetworkV6)
  {
    ipv6 = ip.ToString(); //ipv6
  }


}

转载于:https://www.cnblogs.com/lichuangblog/p/8000181.html

你可能感兴趣的:(unity 获取本机ip地址)