unity 获取本机的IP地址
文章目录
粘贴直接就能用
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;
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论