How to find the IP address of a machine in a Metro app (Windows 8).
Using the code
DNS is not supported by Metro
applications. So to find the IP address in a Metro app implement the following code:
- Import the
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.
var icp = NetworkInformation.GetInternetConnectionProfile();
if (icp != null && icp.NetworkAdapter != null)
var hostname =
hn.IPInformation != null && hn.IPInformation.NetworkAdapter != null
if (hostname != null)
txtKeyWord.Text = hostname.CanonicalName;
Hostname has various properties such as Canonical Name, Display Name
and Raw Name, but they all seem to return the same string. Here
txtKeyWord will give the IP address of the
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.