The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

HostName.HostName constructor

Applies to Windows and Windows Phone

Creates a new HostName object from a string that contains a hostname or an IP address.


var hostName = new Windows.Networking.HostName(hostName);



Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

A string that contains a hostname or an IP address.


This constructor creates a new HostName object. The hostName parameter can contain a hostname or an IP address. A HostName object can be used for a local hostname or a remote hostname.

The hostName parameter can contain one of the following:

  • The name of a host that can be resolved by the Domain Name System (DNS) or by another namespace provider.
  • The name of a host that matches a string in the following file on the local computer: %WINDIR%\\system32\drivers\etc\hosts
  • A string that contains an IPv4 or an IPv6 network address of the host. An IPv4 address string is in dotted-decimal notation ("", for example). An IPv6 address is in hexadecimal notation ("21DA:00D3:0010:2F3B:02AA:00FF:FE28:9C5A", for example).

If the hostName parameter is the "localhost" string, this represents all loopback addresses on the local computer.

The NetworkInformation.GetHostNames method in the Windows.Networking.Connectivity namespace can be used to retrieve a list of host names or IP addresses associated with the local machine. One of these hostnames or IP addresses can then be used for the hostName parameter.

The constructor will fail if the hostName parameter is null or contains an empty string.


Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8


Windows::Networking [C++]



See also




© 2015 Microsoft