Dns.GetHostByName(String) メソッド

定義

注意事項

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

注意事項

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

注意事項

Use GetHostEntry instead

指定した DNS ホスト名の DNS 情報を取得します。Gets the DNS information for the specified DNS host name.

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

パラメーター

hostName
String

ホストの DNS 名。The DNS name of the host.

戻り値

IPHostEntry

hostName で指定したアドレスのホスト情報を格納する IPHostEntry オブジェクト。An IPHostEntry object that contains host information for the address 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.

次の例では、メソッドを使用して、 GetHostByName 指定された dns ホスト名の dns 情報を取得します。The following example uses the GetHostByName method to get the DNS information for the specified DNS host name.

try
{
   IPHostEntry^ hostInfo = Dns::GetHostByName( hostName );
   
   // 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 ( Exception^ e ) 
{
   Console::WriteLine( "Exception caught!!!" );
   Console::WriteLine( "Source : {0}", e->Source );
   Console::WriteLine( "Message : {0}", e->Message );
}
 try
 {
    IPHostEntry hostInfo = Dns.GetHostByName(hostName);
    // 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(Exception e)
 {
     Console.WriteLine("Exception caught!!!");
     Console.WriteLine("Source : " + e.Source);
     Console.WriteLine("Message : " + e.Message);
 }
Public Sub DisplayHostName(hostName As [String])
    Try
        ' Call the GetHostByName method, passing a DNS style host name(for example,
        ' "www.contoso.com") as an argument to obtain an IPHostEntry instance, that 
        ' contains information for the specified host.
        
        Dim hostInfo As IPHostEntry = Dns.GetHostByName(hostName)
        ' 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 Exception
        Console.WriteLine("Exception caught!!!")
        Console.WriteLine(("Source : " + e.Source))
        Console.WriteLine(("Message : " + e.Message))
    End Try

注釈

メソッドは、 GetHostByName インターネット DNS サーバーにホスト情報を照会します。The GetHostByName method queries the Internet DNS server for host information. ホスト名として空の文字列を渡すと、このメソッドはローカルコンピューターの標準ホスト名を取得します。If you pass an empty string as the host name, this method retrieves the standard host name for the local computer.

DNS 情報に非同期にアクセスするには、 BeginGetHostByName メソッドとメソッドを使用し EndGetHostByName ます。For asynchronous access to DNS information, use the BeginGetHostByName and EndGetHostByName methods.

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.

適用対象