参考链接:
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;
}