unity获取手机联网ip

//获取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;
}

你可能感兴趣的:(Unity3d)