Click here to Skip to main content
13,457,828 members
Click here to Skip to main content
Add your own
alternative version


1 bookmarked
Posted 18 Mar 2013

Find IP address in a Metro app (Windows 8)

, 18 Mar 2013
Rate this:
Please Sign up or sign in to vote.
How to find IP address of machine in metro App(Windows 8)


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 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.

 var icp = NetworkInformation.GetInternetConnectionProfile();

if (icp != null && icp.NetworkAdapter != null)
    var hostname =
                hn =>
                hn.IPInformation != null && hn.IPInformation.NetworkAdapter != null
                && hn.IPInformation.NetworkAdapter.NetworkAdapterId
                == icp.NetworkAdapter.NetworkAdapterId);

    if (hostname != null)
        // the ip address
        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 machine (localhost).


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Abhinav Sultania
Software Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180323.1 | Last Updated 18 Mar 2013
Article Copyright 2013 by Abhinav Sultania
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid