Dns.Resolve(String) メソッド

定義

注意事項

Resolve is obsoleted for this type, please use GetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202

注意事項

Resolve is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202

注意事項

Use GetHostEntry instead

DNS ホスト名または IP アドレスを IPHostEntry インスタンスに解決します。Resolves a DNS host name or IP address to an IPHostEntry instance.

public:
 static System::Net::IPHostEntry ^ Resolve(System::String ^ hostName);
[System.Obsolete("Resolve is obsoleted for this type, please use GetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Net.IPHostEntry Resolve (string hostName);
public static System.Net.IPHostEntry Resolve (string hostName);
[System.Obsolete("Resolve is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Net.IPHostEntry Resolve (string hostName);
[System.Obsolete("Use GetHostEntry instead")]
public static System.Net.IPHostEntry Resolve (string hostName);
[<System.Obsolete("Resolve is obsoleted for this type, please use GetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202")>]
static member Resolve : string -> System.Net.IPHostEntry
static member Resolve : string -> System.Net.IPHostEntry
[<System.Obsolete("Resolve is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")>]
static member Resolve : string -> System.Net.IPHostEntry
[<System.Obsolete("Use GetHostEntry instead")>]
static member Resolve : string -> System.Net.IPHostEntry
Public Shared Function Resolve (hostName As String) As IPHostEntry

パラメーター

hostName
String

DNS スタイルのホスト名、または IP アドレス。A DNS-style host name or IP address.

戻り値

IPHostEntry

hostName で指定するホストについてのアドレス情報を格納する IPHostEntry インスタンス。An IPHostEntry instance that contains address information about the host specified in hostName.

属性

例外

hostNamenullです。hostName is null.

hostName の長さが 255 文字を超えています。The length of hostName is greater than 255 characters.

hostName を解決するときにエラーが発生しました。An error is encountered when resolving hostName.

次の例では、メソッドを使用して、 Resolve IP アドレスをインスタンスに解決し IPHostEntry ます。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.
   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 );
}
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
    ' 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

注釈

メソッドは、 Resolve DNS サーバーに対して、ホスト名または ip アドレスに関連付けられた ip アドレスを照会します。The Resolve method queries a DNS server for the IP address associated with a host name or IP address.

hostNameが、複数の IP アドレスに関連付けられている DNS スタイルのホスト名である場合、そのホスト名に解決される最初の ip アドレスのみが返されます。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.

Ipv6Element.Enabledプロパティがに設定されている場合 trueAliases IPHostEntry 返されるインスタンスのプロパティはこのメソッドによって設定されず、常に空になります。If the Ipv6Element.Enabled property is set to true, the Aliases property of the IPHostEntry instance returned is not populated by this method and will always be empty.

注意

このメンバーは、アプリケーションでネットワークトレースを有効にするときにトレース情報を出力します。This member emits trace information when you enable network tracing in your application. 詳細については、「 .NET Framework のネットワークトレース」を参照してください。For more information, see Network Tracing in the .NET Framework.

適用対象