Export (0) Print
Expand All

Dns.GetHostByAddress Method (IPAddress)

NOTE: This method is now obsolete.

Creates an IPHostEntry instance from the specified IPAddress.

Namespace: System.Net
Assembly: System (in system.dll)

'Declaration
<ObsoleteAttribute("GetHostByAddress is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")> _
Public Shared Function GetHostByAddress ( _
	address As IPAddress _
) As IPHostEntry
'Usage
Dim address As IPAddress
Dim returnValue As IPHostEntry

returnValue = Dns.GetHostByAddress(address)
/** @attribute ObsoleteAttribute("GetHostByAddress is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202") */ 
public static IPHostEntry GetHostByAddress (
	IPAddress address
)
ObsoleteAttribute("GetHostByAddress is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202") 
public static function GetHostByAddress (
	address : IPAddress
) : IPHostEntry
Not applicable.

Parameters

address

An IPAddress.

Return Value

An IPHostEntry.

Exception typeCondition

ArgumentNullException

address is a null reference (Nothing in Visual Basic).

SocketException

An error is encountered when resolving address.

NoteNote:

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

The following example creates a IPHostEntry from an IPAddress.

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

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.get_AddressList();

    // Get the alias names of the addresses in the IP address list.
    String alias[] = hostInfo.get_Aliases();

    Console.WriteLine("Host name : " + hostInfo.get_HostName());
    Console.WriteLine("\nAliases :");
    for (int index = 0; index < alias.length; index++) {
        Console.WriteLine(alias.get_Item(index));
    }
    Console.WriteLine("\nIP address list : ");
    for (int index = 0; index < address.length; index++) {
        Console.WriteLine(address.get_Item(index));
    }
}
catch (SocketException e) {
    Console.WriteLine("SocketException caught!!!");
    Console.WriteLine("Source : " + e.get_Source());
    Console.WriteLine("Message : " + e.get_Message());
}
catch (FormatException e) {
    Console.WriteLine("FormatException caught!!!");
    Console.WriteLine("Source : " + e.get_Source());
    Console.WriteLine("Message : " + e.get_Message());
}
catch (ArgumentNullException e) {
    Console.WriteLine("ArgumentNullException caught!!!");
    Console.WriteLine("Source : " + e.get_Source());
    Console.WriteLine("Message : " + e.get_Message());
}
catch (System.Exception e) {
    Console.WriteLine("Exception caught!!!");
    Console.WriteLine("Source : " + e.get_Source());
    Console.WriteLine("Message : " + e.get_Message());
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 1.0, 1.1, 2.0
Obsolete (compiler warning) in 3.0

.NET Compact Framework

Supported in: 1.0
Obsolete (compiler warning) in 2.0

Community Additions

ADD
Show:
© 2014 Microsoft