Export (0) Print
Expand All

IPHostEntry.AddressList Property

Gets or sets a list of IP addresses associated with a host.

[Visual Basic]
Public Property AddressList As IPAddress ()
[C#]
public IPAddress[] AddressList {get; set;}
[C++]
public: __property IPAddress* get_AddressList();
public: __property void set_AddressList(IPAddress*[]);
[JScript]
public function get AddressList() : IPAddress[];
public function set AddressList(IPAddress[]);

Property Value

An array of type IPAddress containing IP addresses that resolve to the host names contained in the Aliases property.

Example

[Visual Basic, C#, C++] The following example uses the AddressList property to access the IP addresses associated with the IPHostEntry.

[Visual Basic] 
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

[C#] 

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

[C++] 
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(S"Host name : {0}", hostInfo->HostName);
      Console::WriteLine(S"IP address List : ");
      for (int index = 0 ; index < hostInfo->AddressList->Length ; index++)
         Console::WriteLine(hostInfo->AddressList->Item[index]);

   } catch (SocketException* e) {
      Console::WriteLine(S"SocketException caught!!!");
      Console::WriteLine(S"Source : {0}", e->Source);
      Console::WriteLine(S"Message : {0}", e->Message);
   } catch (ArgumentNullException* e) {
      Console::WriteLine(S"ArgumentNullException caught!!!");
      Console::WriteLine(S"Source : {0}", e->Source);
      Console::WriteLine(S"Message : {0}", e->Message);
   } catch (Exception* e) {
      Console::WriteLine(S"Exception caught!!!");
      Console::WriteLine(S"Source : {0}", e->Source);
      Console::WriteLine(S"Message : {0}", e->Message);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

IPHostEntry Class | IPHostEntry Members | System.Net Namespace

Show:
© 2015 Microsoft