Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

Public ip address in hololens Build

edited January 2017 in Discussion

Hi guys,

I want to get ip address using c#, in this case i have used 2 or 3 codes.

//code1
Network.Connect("http://google.com");
currentIP = Network.player.externalIP;
Network.Disconnect()
//code2
public string GetIP()
{
string externalIP = "";
externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org/");
externalIP = (new Regex(@\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})).Matches(externalIP)[0].ToString();
return externalIP;
}

//code 3

IPHostEntry IPHost = Dns.GetHostByName(Dns.GetHostName());

lblStatus.Text = "My IP address is " +IPHost.AddressList[0].ToString();

All codes gave me ip address successfully but the problem is that whenever i Build it on hololens the unity editor gave me error.

Please help me to solve out the problem. I want to get ip address on hololens without complexity of errors.

Best Answer

Answers

  • what exactly are you trying to achieve here? public facing IP?

    Healthcare IT professional by day - Indie GameDev for UWP and mobile platforms by night

  • WoliarkWoliark
    edited February 2017

    @Waqarahmed Hi!!! I managed to get the Ip adress of an hostname but i could only test this code within the hololens emulator due to some issue with my network. This code only work outside unity

    //#if !UNITY_EDITOR
        using Windows.Networking;
        using System.Threading.Tasks;
        using Windows.Networking.Sockets;
    //#endif
    
    //#if !UNITY_EDITOR
        async Task GetIPAdressFromHostname(string sHostname, string sPort)
        {
            string  sRemoteHostName = "",
                       sLocalHostName     = "";
    
            HostName host = new HostName(sHostname);
            var eps = await DatagramSocket.GetEndpointPairsAsync(host, sPort);
            foreach (EndpointPair ep in eps)
            {
                sRemoteHostName = ep.LocalHostName.ToString();
                sLocalHostName = ep.RemoteHostName.ToString();
                System.Diagnostics.Debug.WriteLine(sRemoteHostName + " : " + sLocalHostName);
            }
    
            //DO THE THINGS....
        }
    //#endif
    
  • @Waqarahmed Hi!!! I managed to get the Ip adress of an hostname but i could only test this code within the hololens emulator due to some issue with my network. This code only work outside unity

    #if !UNITY_EDITOR
    using Windows.Networking;
    using System.Threading.Tasks;
    using Windows.Networking.Sockets;
    //#endif
    
    //#if !UNITY_EDITOR
    async Task GetIPAdressFromHostname(string sHostname, string sPort)
    {
    string sRemoteHostName = "",
    sLocalHostName = "";
    
        HostName host = new HostName(sHostname);
        var eps = await DatagramSocket.GetEndpointPairsAsync(host, sPort);
        foreach (EndpointPair ep in eps)
        {
            sRemoteHostName = ep.LocalHostName.ToString();
            sLocalHostName = ep.RemoteHostName.ToString();
            System.Diagnostics.Debug.WriteLine(sRemoteHostName + " : " + sLocalHostName);
        }
    
        //DO THE THINGS....
    }
    #endif
    
  • @Waqarahmed Hi!!! I managed to get the Ip adress of an hostname but i could only test this code within the hololens emulator due to some issue with my network. This code only work outside unity

    #if !UNITY_EDITOR
    using Windows.Networking;
    using System.Threading.Tasks;
    using Windows.Networking.Sockets;
    //#endif
    
    //#if !UNITY_EDITOR
    async Task GetIPAdressFromHostname(string sHostname, string sPort)
    {
    string sRemoteHostName = "",
    sLocalHostName = "";
    
        HostName host = new HostName(sHostname);
        var eps = await DatagramSocket.GetEndpointPairsAsync(host, sPort);
        foreach (EndpointPair ep in eps)
        {
            sRemoteHostName = ep.LocalHostName.ToString();
            sLocalHostName = ep.RemoteHostName.ToString();
            System.Diagnostics.Debug.WriteLine(sRemoteHostName + " : " + sLocalHostName);
        }
    
        //DO THE THINGS....
    }
    #endif
    
Sign In or Register to comment.