//获取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
本文介绍了一种使用C#语言获取本地计算机IP地址的方法。通过调用Unity引擎的NetWork.player.ipAddress属性来尝试获取IP地址,并提供了一个备选方案,即利用DNS解析主机名来获取IP地址。





