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)

[ObsoleteAttribute("GetHostByAddress is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")] 
public static IPHostEntry GetHostByAddress (
	IPAddress 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.

 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);
 }

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