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 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...
Insert Header and Footer in Microsoft Excel
Header and Footer in a Excel Sheet can help you to show certain information to the user on each printed page easily. This blog post will demonstr...
How to Convert an Image to Byte Array in C# ?
You can convert an Bitmap image to byte array in C# using the  BinaryReader’s ReadByte method. Here are the steps that you need to follow fo...
powered by RelatedPosts