美文网首页
unity2018.2.0版本之后,获取本机ip的方法更新

unity2018.2.0版本之后,获取本机ip的方法更新

作者: 不过一书生 | 来源:发表于2019-10-31 12:48 被阅读0次

参考链接:

1.https://blog.csdn.net/weixin_30667301/article/details/101425365;

2.https://blog.csdn.net/sinat_39291423/article/details/100733882;

3.https://www.cnblogs.com/qq2351194611/p/11465313.html;


privatestring GetIP()

    {

        NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();

        foreach(NetworkInterface adaterin adapters)

        {

            if (adater.Supports(NetworkInterfaceComponent.IPv4))

            {

                UnicastIPAddressInformationCollection UniCast = adater.GetIPProperties().UnicastAddresses;

                if(UniCast.Count >0)

                {

                    foreach(UnicastIPAddressInformation uniin UniCast)

                    {

                        if(uni.Address.AddressFamily == AddressFamily.InterNetwork)

                        {

                            Debug.Log(uni.Address.ToString());

                            return uni.Address.ToString();

                        }

                    }

                }

            }

        }

        returnnull;

    }

相关文章

网友评论

      本文标题:unity2018.2.0版本之后,获取本机ip的方法更新

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