Mono Class Library: System.Net.Dns Overview | Members

System.Net.Dns.Resolve Method

Resolves a DNS host name or IP address to a System.Net.IPHostEntry instance.

[System.Obsolete("Use GetHostEntry instead")]
public static IPHostEntry Resolve (string hostName)

Parameters

hostName
A string containing a DNS-style host name or IP address.

Returns

A System.Net.IPHostEntry instance containing address information about the host specified in hostName .

Permissions

TypeReason
System.Net.DnsPermissionRequires unrestricted permission for accessing DNS information. This method also asserts unrestricted DnsPermission . See System.Net.DnsPermission and System.Security.Permissions.PermissionState.Unrestricted.

Exceptions

TypeReason
ArgumentNullExceptionhostName is null .
System.Net.Sockets.SocketExceptionAn error was encountered executing the DNS query .
System.Security.SecurityExceptionThe caller does not have permission to access DNS information.

Remarks

The Dns.Resolve(string) method queries a DNS server for the IP address associated with a host name or an IP address in dotted-quad notation.

When hostName is a DNS-style host name associated with multiple IP addresses, only the first IP address that resolves to that host name is returned.

Example

The following example demonstrates the use of the Dns.Resolve(string) method.

C# Example

using System;
using System.Net;

public class DnsTest {
 public static void Main() {
   IPHostEntry hostInfo1 = Dns.Resolve("www.contoso.com");
   DisplayHostInfo(hostInfo1);
   Console.WriteLine();
 }

 public static void DisplayHostInfo(IPHostEntry hostInfo) {
   string[] aliases = hostInfo.Aliases;
   IPAddress[] addresses = hostInfo.AddressList;
   Console.WriteLine("The host name is: {0}", hostInfo.HostName);

   for(int x = 0; x < aliases.Length; x++)
     Console.WriteLine("Alias {0} == {1}", aliases[x], addresses[x]);
 }
}

The output is

The host name is: contoso.com
Alias www.contoso.com == 207.46.230.186

Requirements

Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0