共用方式為


Dns.GetHostByAddress 方法

定義

取得 IP 位址的 DNS 主機資訊。 這些方法現在已經過時。

多載

GetHostByAddress(IPAddress)
已淘汰.
已淘汰.
已淘汰.

從指定的 IPHostEntry 建立 IPAddress 執行個體。

GetHostByAddress(String)
已淘汰.
已淘汰.
已淘汰.

從點分隔的 IP 位址建立 IPHostEntry 執行個體。

GetHostByAddress(IPAddress)

來源:
Dns.cs
來源:
Dns.cs
來源:
Dns.cs

警告

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

警告

GetHostByAddress has been deprecated. Use GetHostEntry instead.

警告

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

從指定的 IPHostEntry 建立 IPAddress 執行個體。

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

參數

address
IPAddress

IPAddress

傳回

IPHostEntry 執行個體。

屬性

例外狀況

addressnull

當解析 address 時,發生錯誤。

範例

下列範例會 IPHostEntryIPAddress建立 。

try
{
   IPAddress^ hostIPAddress = IPAddress::Parse( IpAddressString );
   IPHostEntry^ hostInfo = Dns::GetHostByAddress( hostIPAddress );
   
   // 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 ( FormatException^ e ) 
{
   Console::WriteLine( "FormatException 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
 {
    IPAddress hostIPAddress = IPAddress.Parse(IpAddressString);
    IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress);
    // 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(FormatException e)
 {
Console.WriteLine("FormatException 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 DisplayHostAddress(IpAddressString As [String])
    Try
        Dim hostIPAddress As IPAddress = IPAddress.Parse(IpAddressString)
        
        ' Call the GetHostByAddress(IPAddress) method, passing an IPAddress object as an argument 
        ' to obtain an IPHostEntry instance, containing address information for the specified host.
        
        Dim hostInfo As IPHostEntry = Dns.GetHostByAddress(hostIPAddress)
        ' 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 above 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 FormatException
        Console.WriteLine("FormatException 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

備註

注意

當您在應用程式中啟用網路追蹤時,此成員會發出追蹤資訊。 如需詳細資訊,請參閱 .NET Framework 中的網路追蹤

適用於

GetHostByAddress(String)

來源:
Dns.cs
來源:
Dns.cs
來源:
Dns.cs

警告

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

警告

GetHostByAddress has been deprecated. Use GetHostEntry instead.

警告

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

從點分隔的 IP 位址建立 IPHostEntry 執行個體。

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

參數

address
String

IP 位址。

傳回

IPHostEntry 執行個體。

屬性

例外狀況

addressnull

當解析 address 時,發生錯誤。

address 不是有效的 IP 位址。

備註

注意

當您在應用程式中啟用網路追蹤時,此成員會發出追蹤資訊。 如需詳細資訊,請參閱 .NET Framework 中的網路追蹤

適用於