locked
how to get the local IP address in Metro?

    Question

  • as the title, I want to get the local ip address, but I haven't found the APIs.

    mada

    Monday, August 27, 2012 2:31 AM

Answers

  • Hello,

    As far as I know, you can enumerate the hostname in NetworkInformation.
    The IP address is a part of hostnames. Please follow this codes.

    	auto hostNames=Windows::Networking::Connectivity::NetworkInformation::GetHostNames();
    
    	std::for_each(begin(hostNames), end(hostNames), [this](Windows::Networking::HostName^ hostname)
            {
    			if (hostname->IPInformation!=nullptr)
                {
    				String^ ipaddress=hostname->DisplayName;
    			}
            });

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Jesse Jiang Thursday, August 30, 2012 6:12 AM
    Monday, August 27, 2012 10:37 AM

All replies

  • Hello,

    As far as I know, you can enumerate the hostname in NetworkInformation.
    The IP address is a part of hostnames. Please follow this codes.

    	auto hostNames=Windows::Networking::Connectivity::NetworkInformation::GetHostNames();
    
    	std::for_each(begin(hostNames), end(hostNames), [this](Windows::Networking::HostName^ hostname)
            {
    			if (hostname->IPInformation!=nullptr)
                {
    				String^ ipaddress=hostname->DisplayName;
    			}
            });

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Jesse Jiang Thursday, August 30, 2012 6:12 AM
    Monday, August 27, 2012 10:37 AM
  • HostName class has three properties CanonicalName,DisplayName, RawName all this are string type. So how can I get IP address in integer like winsock (inet_addr() ). Actually what are differences/purposes of CanonicalName,DisplayName, RawName ?

    If I create a object using domain name , is it possible to retrieve corresponding ip address in metro?

    Tuesday, August 28, 2012 4:33 AM
  • All APIs accessible to Metro style apps are IP version agnostic, dealing with addresses in string form.   So if you want it in binary you can do it yourself, but it's not recommended to do so, since that tends to result in apps that don't work correctly, e.g. with IPv6.

    An application can retrieve the IP addresses (as HostName objects) for a given domain name using DatagramSocket.GetEndpointPairsAsync().

    Saturday, September 01, 2012 3:44 AM