Click here to Skip to main content
Click here to Skip to main content

How to get the IP address in Modern UI applications

By , 23 Dec 2012
Rate this:
Please Sign up or sign in to vote.

This small function shows how to get the IPv4 address in Modern UI applications that are targeting the new Windows Store. 

public string GetIPAddress()
    // Get a list of host names associated with the local machine
    IReadOnlyList<Windows.Networking.HostName> hostNames = Windows.Networking.Connectivity.NetworkInformation.GetHostNames();

    // The names can be one of four different types: DomainName, Ipv4, Ipv6, Bluetooth
    foreach (Windows.Networking.HostName name in hostNames)
        if (name.Type == Windows.Networking.HostNameType.Ipv4)
            return name.DisplayName;

    return string.Empty; ;

The usage cannot be simpler

string ip = GetIPAddress();


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

About the Author

Igor Vigdorchik
Web Developer
United States United States
No Biography provided

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140421.2 | Last Updated 23 Dec 2012
Article Copyright 2012 by Igor Vigdorchik
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid