Export (0) Print
Expand All
0 out of 4 rated this helpful - Rate this topic

Dns.Resolve Method

NOTE: This method is now obsolete.

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

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

[ObsoleteAttribute("Resolve is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")] 
public static IPHostEntry Resolve (
	string hostName
)
/** @attribute ObsoleteAttribute("Resolve is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202") */ 
public static IPHostEntry Resolve (
	String hostName
)
ObsoleteAttribute("Resolve is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202") 
public static function Resolve (
	hostName : String
) : IPHostEntry
Not applicable.

Parameters

hostName

A DNS-style host name or IP address.

Return Value

An IPHostEntry instance that contains address information about the host specified in hostName.
Exception typeCondition

ArgumentNullException

hostName is a null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

The length of hostName is greater than 126 characters.

SocketException

An error is encountered when resolving hostName.

The Resolve method queries a DNS server for the IP address associated with a host name or IP address.

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.

NoteNote:

This member emits trace information when you enable network tracing in your application. For more information, see Network Tracing.

The following example uses the Resolve method to resolve an IP address to an IPHostEntry instance.

try {
    IPHostEntry hostInfo = Dns.Resolve(hostString);
    // Get the IP address list that resolves to the host names contained in the 
    // Alias property.
    IPAddress[] address = hostInfo.AddressList;
    // Get the alias names of the addresses in the IP address list.
    String[] alias = hostInfo.Aliases;

    Console.WriteLine("Host name : " + hostInfo.HostName);
    Console.WriteLine("\nAliases : ");
    for(int index=0; index < alias.Length; index++) {
      Console.WriteLine(alias[index]);
    } 
    Console.WriteLine("\nIP Address list :");
    for(int index=0; index < address.Length; index++) {
       Console.WriteLine(address[index]);
    }
 }
 catch(SocketException e) 
 {
    Console.WriteLine("SocketException caught!!!");
    Console.WriteLine("Source : " + e.Source);
    Console.WriteLine("Message : " + e.Message);
 }
 catch(ArgumentNullException e)
 {
Console.WriteLine("ArgumentNullException caught!!!");
    Console.WriteLine("Source : " + e.Source);
    Console.WriteLine("Message : " + e.Message);
 }
 catch(NullReferenceException e)
 {
     Console.WriteLine("NullReferenceException caught!!!");
     Console.WriteLine("Source : " + e.Source);
     Console.WriteLine("Message : " + e.Message);
 }
 catch(Exception e)
 {
     Console.WriteLine("Exception caught!!!");
     Console.WriteLine("Source : " + e.Source);
     Console.WriteLine("Message : " + e.Message);
 }

try {
    IPHostEntry hostInfo = Dns.Resolve(hostString);

    // Get the IP address list that resolves to the host  
    // names contained in the Alias property.
    IPAddress address[] = hostInfo.get_AddressList();

    // Get the alias names of the addresses in the IP address list.
    String alias[] = hostInfo.get_Aliases();

    Console.WriteLine("Host name : " + hostInfo.get_HostName());
    Console.WriteLine("\nAliases : ");
    for (int index = 0; index < alias.length; index++) {
        Console.WriteLine(alias.get_Item(index));
    }
    Console.WriteLine("\nIP Address list :");
    for (int index = 0; index < address.length; index++) {
        Console.WriteLine(address.get_Item(index));
    }
}
catch (SocketException e) {
    Console.WriteLine("SocketException caught!!!");
    Console.WriteLine("Source : " + e.get_Source());
    Console.WriteLine("Message : " + e.get_Message());
}
catch (ArgumentNullException e) {
    Console.WriteLine("ArgumentNullException caught!!!");
    Console.WriteLine("Source : " + e.get_Source());
    Console.WriteLine("Message : " + e.get_Message());
}
catch (NullReferenceException e) {
    Console.WriteLine("NullReferenceException caught!!!");
    Console.WriteLine("Source : " + e.get_Source());
    Console.WriteLine("Message : " + e.get_Message());
}
catch (System.Exception e) {
    Console.WriteLine("Exception caught!!!");
    Console.WriteLine("Source : " + e.get_Source());
    Console.WriteLine("Message : " + e.get_Message());
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 1.0, 1.1, 2.0
Obsolete (compiler warning) in 3.0

.NET Compact Framework

Supported in: 1.0
Obsolete (compiler warning) in 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.