Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to find IpAddress of my WebSite

Discussion in 'Scripting' started by Alexander21, Mar 21, 2019.

  1. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    302
    How to Find the IpAddress in Unity

    Hi All


    I am working in unity 2018. In My project i have to find my website Address. I have used this code to find the web address.


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using System.Net;

    public class IpAddressFind : MonoBehaviour {

    // Use this for initialization
    //public string url=
    public string url="https://www.friendslearn.com";
    void Start () {
    GetIP(url);
    }



    public static string GetIP(string url) {
    Debug.Log("GETIp");
    Debug.Log("String URL" +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");
    Debug.Log(hosts.AddressList[0].ToString());
    }

    } catch {
    Debug.Log ("Could not get IP for URL " + url);
    }
    return null;
    }





    // Update is called once per frame
    void Update () {

    }
    }

    Actually my website is working in amazon ec2 and i am using nameserver in cloudflare. When i run the code. It returns the cloud flare web address. actually my web address is 13.17.222.129. But it returns the cloudflare WebAddress.

    How to find my ec2 address?

    EDIT:I am using old code. Is there any new Api to find WebSite Address.IN UNITY 2018...
     
    Last edited: Mar 22, 2019
  2. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Supposing you're supplying the link to your EC2 instance through CloudFlare, it might be helpful to look at this blog post (https://securitytrails.com/blog/ip-address-behind-cloudflare). In short, it's intentionally difficult to find the original IP behind CloudFlare, as it's protecting the IP from potential dangers. Supposing you want the IP address of the EC2 instance you may need to directly link it in the code, or make a lambda method and make a API Gateway to access it. However the question stands what are you trying to do with the original IP? You might find a better way to do it.
     
  3. Alexander21

    Alexander21

    Joined:
    Dec 14, 2015
    Posts:
    302
    Thanks Nigey For You Reply...

    Actually I am passing my ec2 address in php. I am putting http://13.17.222.129./FileGet.php... and all my databases are stored in this address.

    This is creating a Warning in my build. you are using non secure. and also when i try to change my ip address. the old app users are totally cant login .

    So i am decide to pass my website address. and then i am try to pass like https://mywebsite/fileget.php...

    So this will avoid warning errors and also when i change my site also. The previous users wont get any problem.

    So only i am trying to find my IPAddress...

    You have quote this address. But it is highly difficult. So is there any way i can do through unity.

    This is my problem i have mentioned.

    thanks for you reply...