英語で読む

次の方法で共有


Dns.Resolve(String) メソッド

定義

注意事項

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

注意事項

Resolve has been deprecated. Use GetHostEntry instead.

注意事項

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

DNS ホスト名または IP アドレスを IPHostEntry インスタンスに解決します。

C#
[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);
C#
[System.Obsolete("Resolve has been deprecated. Use GetHostEntry instead.")]
public static System.Net.IPHostEntry Resolve(string hostName);
C#
[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);
C#
public static System.Net.IPHostEntry Resolve(string hostName);

パラメーター

hostName
String

DNS スタイルのホスト名、または IP アドレス。

戻り値

hostName で指定するホストについてのアドレス情報を格納する IPHostEntry インスタンス。

属性

例外

hostNamenullです。

hostName の長さが 255 文字を超えています。

hostName を解決するときにエラーが発生しました。

次の例では、 メソッドを Resolve 使用して IP アドレスをインスタンスに IPHostEntry 解決します。

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);
 }

注釈

メソッドは Resolve 、ホスト名または IP アドレスに関連付けられている IP アドレスを DNS サーバーに照会します。

が複数の IP アドレスに関連付けられた DNS スタイルのホスト名である場合 hostName 、そのホスト名に解決される最初の IP アドレスのみが返されます。

プロパティが Ipv6Element.Enabledtrue設定されている場合、 Aliases 返されるインスタンスの IPHostEntry プロパティはこのメソッドによって設定されず、常に空になります。

注意

このメンバーは、アプリケーションでネットワーク トレースを有効にすると、トレース情報を出力します。 詳細については、「 .NET Framework でのネットワーク トレース」を参照してください。

適用対象

製品 バージョン (廃止)
.NET (Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9)
.NET Framework 1.1 (2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1)
.NET Standard (2.0, 2.1)