How to get IP address in Windows Phone 8 and Windows 8.1 app

Windows Phone 8 provides an easy way to identify the IP address of the phone from the Windows Phone App. Note that there are possibilities of having multiple network interfaces on your Windows Phone. For example, the Windows Phone Emulator has 3 network interfaces as shown in the screenshot below. The code snippet tries to retrieve the first one which is added to the List.

Windows 8

DNS is not supported by Metro applications. So to find the IP address in a Metro app import the Windows.Networking.Connectivity namespace. NetworkInformation.GetInternetConnectionProfile retrieves the connection profile associated with the internet connection currently used by the local machine. NetworkInformation.GetHostNames retrieves a list of host names. Hostname has various properties such as Canonical Name, Display Name and Raw Name, but they all seem to return the same string. Here ipadd will give the IP address of the machine (localhost). The code below lets you fetch the IP address of the local machine.    

Here’s a screen shot of the app showing the IP address in a textbox.

Get the full source code of the solution with Windows Phone 8 and Window 8.1 projects in it.

Download full project source code IP-Address.zip