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

Vivek Maskara

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

  • Pingback: How to get IP address in Windows Phone 8 and Windows 8.1 app()

  • Ngugi Ndung’u

    Hello everyone.
    I am making great progress in windows phone 8 app development.
    The only thing I wanna learn now is to make apps with server and client side.
    I am good in php and mysql and I would love to have someone point me to a resource to help me learn.
    To be precise I wanna know how to upload and download images from a server and display it on windows phone.

    • Yes Ngugi I fully got your point. We will soon add a few tutorials specifically for these things. Till then you may find this article useful If you are good at php and mysql then creating web-services would be easy for you. So you can create web-services for data in your server and parse XML to show the data in your app. Moreover we will add a tutorial to download images from web(btw its very simple…)

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