How to Get the IP Address of the Windows Phone 8 Programatically using C#?

The Windows Phone 8 SDK provides an easier way to identify the IP address of the phone from the Windows Phone App.

Below is a function that retrieves the IP Address of the Windows Phone 8 using C#? 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.

How to Get the IP Address of the Windows Phone 8 Programatically using C#?

private void Button_Click_1(object sender, RoutedEventArgs e)
   IPAddress ObjIPAddress = GetIPAddress();
   string IPAddress = ObjIPAddress.ToString();
// Function to get the IP Address from Windows Phone 8
public IPAddress GetIPAddress()
   List<string> IpAddress = new List<string>();
   var Hosts = Windows.Networking.Connectivity.NetworkInformation.GetHostNames().ToList();
   foreach (var Host in Hosts)
      string IP = Host.DisplayName;
   IPAddress address = IPAddress.Parse(IpAddress.Last());
   return address;

One Response

Leave a Reply


Related Posts

How to wrap text using Wrap Text Command in Excel ?
Microsoft Excel provides the Wrap Text command that lets the users to quickly wrap long sentences and lets the users view the full content of the...
How to change the orientation of text in cells in Excel ?
There are times when you need to change the orientation of the text with in the cell in Microsoft Excel and you can do that by following the step...
How to turn off Intellisense filtering in Visual Studio 2017 ?
In one of my previous blog posts , I provided an insight on the intellisense filtering feature in Visual Studio 2017. If you are one of those dev...
powered by RelatedPosts