请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
.NET Framework
Dns 类
Dns 方法
 Resolve 方法
全部折叠/全部展开 全部折叠
此页面仅适用于
Microsoft Visual Studio 2008/.NET Framework 3.5

同时提供下列产品的其他版本:
.NET Framework 类库
Dns..::.Resolve 方法

更新:2007 年 11 月

注意:此 API 现在已过时。

将 DNS 主机名或 IP 地址解析为 IPHostEntry 实例。

命名空间:  System.Net
程序集:  System(在 System.dll 中)

Visual Basic(声明)
<ObsoleteAttribute("Resolve is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")> _
Public Shared Function Resolve ( _
    hostName As String _
) As IPHostEntry
Visual Basic (用法)
Dim hostName As String
Dim returnValue As IPHostEntry

returnValue = Dns.Resolve(hostName)
C#
[ObsoleteAttribute("Resolve is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public static IPHostEntry Resolve(
    string hostName
)
Visual C++
[ObsoleteAttribute(L"Resolve is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public:
static IPHostEntry^ Resolve(
    String^ hostName
)
J#
/** @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
)
JScript
public static function Resolve(
    hostName : String
) : IPHostEntry

参数

hostName
类型:System..::.String

DNS 样式的主机名或 IP 地址。

返回值

类型:System.Net..::.IPHostEntry

一个 IPHostEntry 实例,包含有关 hostName 中指定的主机的地址信息。

异常条件
ArgumentNullException

hostNamenullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing

ArgumentOutOfRangeException

hostName 的长度超过 126 个字符。

SocketException

解析 hostName 时遇到错误。

Resolve 方法在 DNS 服务器中查询与某个主机名或 IP 地址关联的 IP 地址。

hostName 是 DNS 样式的主机名并且与多个 IP 地址关联时,仅返回解析为该主机名的第一个 IP 地址。

说明:

当应用程序中启用了网络跟踪时,此成员会发出跟踪信息。有关更多信息,请参见 网络跟踪

下面的示例使用 Resolve 方法将 IP 地址解析为 IPHostEntry 实例。

Visual Basic
Try
    ' Call the Resolve method passing a DNS style host name or an IP address in 
    ' dotted-quad notation (for example, "www.contoso.com" or "207.46.131.199") to 
    ' obtain an IPHostEntry instance that contains address information for the 
    ' specified host.
    Dim hostInfo As IPHostEntry = Dns.Resolve(hostString)
    ' Get the IP address list that resolves to the host names contained in the Alias 
    ' property.
    Dim address As IPAddress() = hostInfo.AddressList
    ' Get the alias names of the addresses in the IP address list.
    Dim [alias] As [String]() = hostInfo.Aliases

    Console.WriteLine(("Host name : " + hostInfo.HostName))
    Console.WriteLine(ControlChars.Cr + "Aliases : ")
    Dim index As Integer
    For index = 0 To [alias].Length - 1
        Console.WriteLine([alias](index))
    Next index
    Console.WriteLine(ControlChars.Cr + "IP Address list :")

    For index = 0 To address.Length - 1
        Console.WriteLine(address(index))
    Next index
Catch e As SocketException
    Console.WriteLine("SocketException caught!!!")
    Console.WriteLine(("Source : " + e.Source))
    Console.WriteLine(("Message : " + e.Message))
Catch e As ArgumentNullException
    Console.WriteLine("ArgumentNullException caught!!!")
    Console.WriteLine(("Source : " + e.Source))
    Console.WriteLine(("Message : " + e.Message))
Catch e As NullReferenceException
    Console.WriteLine("NullReferenceException caught!!!")
    Console.WriteLine(("Source : " + e.Source))
    Console.WriteLine(("Message : " + e.Message))
Catch e As Exception
    Console.WriteLine("Exception caught!!!")
    Console.WriteLine(("Source : " + e.Source))
    Console.WriteLine(("Message : " + e.Message))
End Try
C#
     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);
      }
Visual C++
try
{
   IPHostEntry^ hostInfo = Dns::Resolve( hostString );

   // Get the IP address list that resolves to the host names contained in the
   // Alias property.
   array<IPAddress^>^address = hostInfo->AddressList;

   // Get the alias names of the addresses in the IP address list.
   array<String^>^alias = hostInfo->Aliases;
   Console::WriteLine( "Host name : {0}", 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 : {0}", e->Source );
   Console::WriteLine( "Message : {0}", e->Message );
}
catch ( ArgumentNullException^ e ) 
{
   Console::WriteLine( "ArgumentNullException caught!!!" );
   Console::WriteLine( "Source : {0}", e->Source );
   Console::WriteLine( "Message : {0}", e->Message );
}
catch ( NullReferenceException^ e ) 
{
   Console::WriteLine( "NullReferenceException caught!!!" );
   Console::WriteLine( "Source : {0}", e->Source );
   Console::WriteLine( "Message : {0}", e->Message );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( "Exception caught!!!" );
   Console::WriteLine( "Source : {0}", e->Source );
   Console::WriteLine( "Message : {0}", e->Message );
}
J#
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 Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

.NET Framework

受以下版本支持:1.1、1.0
在 3.5 中过时(编译器警告)
在 3.5 SP1 中过时(编译器警告)
在 3.0 中过时(编译器警告)
在 3.0 SP1 中过时(编译器警告)
在 2.0 中过时(编译器警告)
在 2.0 SP1 中过时(编译器警告)

.NET Compact Framework

受以下版本支持:1.0
在 3.5 中过时(编译器警告)
在 2.0 中过时(编译器警告)
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利 | 商标 | 隐私权声明
Page view tracker