Dns.GetHostByAddress Dns.GetHostByAddress Dns.GetHostByAddress Dns.GetHostByAddress Method

Definition

Gets DNS host information for an IP address. These methods are now obsolete.

Overloads

GetHostByAddress(IPAddress) GetHostByAddress(IPAddress) GetHostByAddress(IPAddress) GetHostByAddress(IPAddress)

Creates an IPHostEntry instance from the specified IPAddress.

GetHostByAddress(String) GetHostByAddress(String) GetHostByAddress(String) GetHostByAddress(String)

Creates an IPHostEntry instance from an IP address.

GetHostByAddress(IPAddress) GetHostByAddress(IPAddress) GetHostByAddress(IPAddress) GetHostByAddress(IPAddress)

Warning

This API is now obsolete.

Creates an IPHostEntry instance from the specified IPAddress.

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

Parameters

Returns

Exceptions

An error is encountered when resolving address.

Examples

The following example creates a IPHostEntry from an IPAddress.

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 'DisplayHostAddress

Remarks

Note

This member emits trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

Security

DnsPermission
for accessing DNS information. Associated enumeration: Unrestricted

GetHostByAddress(String) GetHostByAddress(String) GetHostByAddress(String) GetHostByAddress(String)

Warning

This API is now obsolete.

Creates an IPHostEntry instance from an IP address.

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

Parameters

address
String String String String

An IP address.

Returns

Exceptions

An error is encountered when resolving address.

address is not a valid IP address.

Remarks

Note

This member emits trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

Security

DnsPermission
for accessing DNS information. Associated enumeration: Unrestricted

Applies to