Search code examples
cordovawindows-phone-8phonegap-plugins

How can I get the local ip address on a wp8 with cordova (phonegap)?


How can I get the local ip address on a wp8 with cordova (phonegap) ? Maybe I need the answer of the following thread, but in C# Get local IP address of client using javascript


Solution

  • If you can call to C# code from cordova, then in C# it's implemented like this:

    Windows.Networking.Connectivity.NetworkInformation.GetHostNames();
    

    The resulting collection contains information about all network interfaces of the phone, via instances of Windows.Networking.HostName class. You can get IP addresses from that instance: Windows.Networking.HostName.CanonicalName.

    Be warned that you'll probably receive several interfaces in the response. Most probably, you'll get one for cellular network modem and one for Wi-Fi network. If you need to distinguish between them, you can use Windows.Networking.HostName.IPInformation.NetworkAdapter.IanaInterfaceType property. For Wi-Fi, it will contain value 71. For cellular (at least for my current phone and carrier) it displays 244. The full list of values could be found on IANA website.