This[
^] answer should help you along your way in Win8.
The gist of the answer is this:
I found the information you need using NetworkInformation and HostName.
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. It's not obvious but this includes IPv4 and IPv6 addresses as strings.
Using this information we can get the IP address of the network adapter connected to the internet like this:
public static string CurrentIPAddress()
{
var icp = NetworkInformation.GetInternetConnectionProfile();
if(icp != null && icp.NetworkAdapter != null)
{
var hostname =
NetworkInformation.GetHostNames().SingleOrDefault(
hn =>
hn.NetworkAdapter != null &&
hn.NetworkAdapter.NetworkAdapterId ==
icp.NetworkAdapter.NetworkAdapterId);
if(hostname != null)
{
return hostname.CanonicalName;
}
}
return string.Empty;
}
Note that HostName has properties CanonicalName, DisplayName and RawName, but they all seem to return the same string.
We can also get addresses for multiple adapters with code similar to this:
IEnumerable<connectionprofile> profiles =
NetworkInformation.GetConnectionProfiles().Where(
p => p.NetworkAdapter != null).ToList();
IEnumerable<hostname> hostnames =
NetworkInformation.GetHostNames().Where(h=>h.NetworkAdapter != null).ToList();
foreach (ConnectionProfile profile in profiles)
{
Debug.WriteLine(
"{0}, {1}",
profile.ProfileName,
hostnames.Single(hn =>
hn.NetworkAdapter.NetworkAdapterId ==
profile.NetworkAdapter.NetworkAdapterId).CanonicalName);
}
If I connect a wireless network as well as my wired network then on my machine I get:
Wired Ethernet Connection, 192.168.1.71
My SSID, 192.168.1.72