Я работаю в Unity 2018. В моем проекте мне нужно найти адрес моего сайта. Я использовал этот код, чтобы найти веб-адрес.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Net;
public class IpAddressFind : MonoBehaviour {
public string url="https://www.friendslearn.com";
void Start () {
GetIP(url);
}
public static string GetIP(string url) {
url = url.Replace("http://", ""); //remove http://
url = url.Replace("https://", ""); //remove https://
url = url.Substring(0, url.IndexOf("/")); //remove everything after the first /
try {
IPHostEntry hosts = Dns.GetHostEntry(url);
Debug.Log(hosts.AddressList.Length);
Debug.Log(hosts.HostName);
if(hosts.AddressList.Length > 0)
{
Debug.Log(hosts.AddressList[0].ToString());
Debug.Log("Final");
}
} catch {
Debug.Log ("Could not get IP for URL " + url);
}
return null;
}
}
Возвращает адрес CloudFlare.
На самом деле мой сайт работает в Amazon EC2, и я использую сервер имен в CloudFlare. Когда я запускаю код, он возвращает веб-адрес CloudFlare. На самом деле мой веб-адрес 13.37.202.259. Но он возвращает IP CloudFlare.
Как найти мой адрес EC2?
РЕДАКТИРОВАТЬ: я использую старый код. Есть ли новый API для поиска моего IP-адреса. В Unity 2018.