美文网首页
Unity获取本机IP

Unity获取本机IP

作者: 玄策丶 | 来源:发表于2022-12-03 15:06 被阅读0次
    /// <summary>
        /// 获取本机IP
        /// </summary>
        /// <returns></returns>
        private string GetIP()
        {
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adater in adapters)
            {
                if (adater.Supports(NetworkInterfaceComponent.IPv4))
                {
                    UnicastIPAddressInformationCollection UniCast = adater.GetIPProperties().UnicastAddresses;
                    if (UniCast.Count > 0)
                    {
                        foreach (UnicastIPAddressInformation uni in UniCast)
                        {
                            if (uni.Address.AddressFamily == AddressFamily.InterNetwork)
    
                            {
                                Debug.Log(uni.Address.ToString());
                                return uni.Address.ToString();
                            }
                        }
                    }
                }
            }
            return null;
        }
    

    相关文章

      网友评论

          本文标题:Unity获取本机IP

          本文链接:https://www.haomeiwen.com/subject/svdjxdtx.html