private string GetIP()
{
string _ip = string.Empty;
foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
{
NetworkInterfaceType _type1 = NetworkInterfaceType.Wireless80211;
NetworkInterfaceType _type2 = NetworkInterfaceType.Ethernet;
if ((item.NetworkInterfaceType == _type1 || item.NetworkInterfaceType == _type2) && item.OperationalStatus == OperationalStatus.Up)
{
foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)
{
//IPv4
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
{
_ip = ip.Address.ToString();
}
//IPv6
else if (ip.Address.AddressFamily == AddressFamily.InterNetworkV6)
{
_ip = ip.Address.ToString();
}
}
}
}
return _ip;
}
Unity获取IP地址
最新推荐文章于 2024-07-29 18:02:37 发布