Click here to Skip to main content
12,303,581 members (76,965 online)
Click here to Skip to main content
Add your own
alternative version

Stats

15.4K views
19 bookmarked
Posted

How to get the IP address in Modern UI applications

, 29 Apr 2014 CPOL
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

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
Carsten V2.029-Apr-14 23:20
memberCarsten V2.029-Apr-14 23:20 
GeneralRe: My vote of 5 Pin
Igor Vigdorchik1-May-14 17:15
memberIgor Vigdorchik1-May-14 17:15 
GeneralMy vote of 5 Pin
Volynsky Alex29-Apr-14 23:02
professionalVolynsky Alex29-Apr-14 23:02 
GeneralRe: My vote of 5 Pin
Igor Vigdorchik1-May-14 17:15
memberIgor Vigdorchik1-May-14 17:15 
GeneralRe: My vote of 5 Pin
Volynsky Alex1-May-14 22:51
professionalVolynsky Alex1-May-14 22:51 
GeneralRe: My vote of 5 Pin
Igor Vigdorchik2-May-14 2:35
memberIgor Vigdorchik2-May-14 2:35 
GeneralRe: My vote of 5 Pin
Volynsky Alex2-May-14 12:08
professionalVolynsky Alex2-May-14 12:08 
SuggestionA little bit short for an article Pin
phil.o29-Apr-14 22:45
professionalphil.o29-Apr-14 22:45 
GeneralRe: A little bit short for an article Pin
Igor Vigdorchik1-May-14 16:05
memberIgor Vigdorchik1-May-14 16:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web02 | 2.8.160530.1 | Last Updated 29 Apr 2014
Article Copyright 2012 by Igor Vigdorchik
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid