IPHostEntry.HostName IPHostEntry.HostName IPHostEntry.HostName IPHostEntry.HostName Property

定義

ホストの DNS 名を取得または設定します。Gets or sets the DNS name of the host.

public:
 property System::String ^ HostName { System::String ^ get(); void set(System::String ^ value); };
public string HostName { get; set; }
member this.HostName : string with get, set
Public Property HostName As String

プロパティ値

サーバーのプライマリ ホスト名を格納する文字列。A string that contains the primary host name for the server.

次の例では、HostNameプライマリ ホスト名を取得するプロパティ。The following example uses the HostName property to retrieve the primary host name.

void GetIpAddressList( String^ hostString )
{
   try
   {
      // Get 'IPHostEntry' object containing information
      // like host name, IP addresses, aliases for a host.
      IPHostEntry^ hostInfo = Dns::GetHostByName( hostString );
      Console::WriteLine( "Host name : {0}", hostInfo->HostName );
      Console::WriteLine( "IP address List : " );
      for ( int index = 0; index < hostInfo->AddressList->Length; index++ )
         Console::WriteLine( hostInfo->AddressList[ 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 );
   }
}

public void GetIpAddressList(String hostString)
{
 try 
 {
  // Get 'IPHostEntry' object containing information like host name, IP addresses, aliases for a host.
  IPHostEntry hostInfo = Dns.GetHostByName(hostString);
  Console.WriteLine("Host name : " + hostInfo.HostName);
  Console.WriteLine("IP address List : ");
  for(int index=0; index < hostInfo.AddressList.Length; index++)
  {
   Console.WriteLine(hostInfo.AddressList[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 GetIpAddressList(hostString As [String])
    Try
        ' Get 'IPHostEntry' object which contains information like host name, IP addresses, aliases
 ' for specified url
        Dim hostInfo As IPHostEntry = Dns.GetHostByName(hostString)
        Console.WriteLine(("Host name : " + hostInfo.HostName))
        Console.WriteLine("IP address List : ")
        Dim index As Integer
        For index = 0 To hostInfo.AddressList.Length - 1
            Console.WriteLine(hostInfo.AddressList(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
End Sub 'GetIpAddressList

注釈

HostNameプロパティには、サーバーのプライマリ ホスト名が含まれています。The HostName property contains the primary host name for a server. サーバーの DNS エントリには、追加のエイリアスが定義されている場合に使用されます、Aliasesプロパティ。If the DNS entry for the server defines additional aliases, they will be available in the Aliases property.

適用対象