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

Vivek Maskara

I am pursuing BTech in Software Engineering from Delhi Technological University. I develop apps, create websites and blog about my app experiences.

Read more:
How to create your first Windows Phone app
How to change the App name and Tile name of your Windows phone app
Data binding in Windows Phone app – One way binding
Close