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
  }


}

posted @ 2017-12-07 17:37  游戏鼻祖  阅读(6396)  评论(0编辑  收藏  举报