HostEntry Class

System.Net
Represents the DNS (Domain Name System) entry for a host. This class cannot be inherited.
C# Syntax
public sealed class HostEntry
Note: This class is obsolete. For new development, use the System.Net.Dns class to resolve host names.

Remarks

The HostEntry class contains information about a host, including its host name and a list of IP addresses associated with it. You can use this class to programmatically access DNS information.

You can create an instance of the HostEntry class by calling the Dns.GetHostEntry method.

Members

Properties

Methods

Example

// This example demonstrates how to resolve a host name and display its information. // Note: This code uses the obsolete Dns.GetHostEntry overload for HostEntry. // For new development, use the Dns.GetHostEntryAsync or Dns.GetHostAddresses methods. using System; using System.Net; public class HostEntryExample { public static void Main(string[] args) { try { // Resolve the host name for "www.microsoft.com" HostEntry hostInfo = Dns.GetHostEntry("www.microsoft.com"); Console.WriteLine($"Host Name: {hostInfo.HostName}"); Console.WriteLine("IP Addresses:"); foreach (IPAddress ip in hostInfo.AddressList) { Console.WriteLine($" - {ip}"); } if (hostInfo.Aliases.Length > 0) { Console.WriteLine("Aliases:"); foreach (string alias in hostInfo.Aliases) { Console.WriteLine($" - {alias}"); } } } catch (SocketException e) { Console.WriteLine($"SocketException caught: {e.Message}"); } catch (Exception e) { Console.WriteLine($"An error occurred: {e.Message}"); } } }

Requirements

Namespace: System.Net
Assembly: System (in System.dll)