//获取ip地址
public static string GetIPAddress()
{
string ip = NetWork.player.ipAddress;
if(ip == null || ip == "")
{
try
{
string hostName = System.Net.Dns.GetHostName();
if(hostName != null)
{
System.Net.IPAddress[] ips = System.Net.Dns.GetHostAddresses(hostName);
if(ips.Length > 0)
{
ip = ips[0].ToString();
}
}
else
{
ip = "";
}
}
catch(Exception e)
{
ip = "";
}
}
return ip;
}
unity获取手机联网ip
最新推荐文章于 2025-06-24 10:22:05 发布
本文介绍了一种使用C#语言获取本地计算机IP地址的方法。通过调用Unity引擎的NetWork.player.ipAddress属性来尝试获取IP地址,并提供了一个备选方案,即利用DNS解析主机名来获取IP地址。
1388

被折叠的 条评论
为什么被折叠?



