Click here to Skip to main content
Click here to Skip to main content
Go to top

How to get the IP address in Modern UI applications

, 29 Apr 2014
Rate this:
Please Sign up or sign in to vote.
Presents a simple function to get the IPv4 address

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();

License

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

Share

About the Author

Igor Vigdorchik
Web Developer
United States United States
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 PinmemberCarsten V2.029-Apr-14 23:20 
GeneralRe: My vote of 5 PinmemberIgor Vigdorchik1-May-14 17:15 
GeneralMy vote of 5 PinprofessionalVolynsky Alex29-Apr-14 23:02 
GeneralRe: My vote of 5 PinmemberIgor Vigdorchik1-May-14 17:15 
GeneralRe: My vote of 5 PinprofessionalVolynsky Alex1-May-14 22:51 
GeneralRe: My vote of 5 PinmemberIgor Vigdorchik2-May-14 2:35 
GeneralRe: My vote of 5 PinprofessionalVolynsky Alex2-May-14 12:08 
SuggestionA little bit short for an article Pinprofessionalphil.o29-Apr-14 22:45 
GeneralRe: A little bit short for an article PinmemberIgor Vigdorchik1-May-14 16:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 29 Apr 2014
Article Copyright 2012 by Igor Vigdorchik
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid