IPHostEntry.AddressList 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定與主機關聯的 IP 位址清單。
public:
property cli::array <System::Net::IPAddress ^> ^ AddressList { cli::array <System::Net::IPAddress ^> ^ get(); void set(cli::array <System::Net::IPAddress ^> ^ value); };
public System.Net.IPAddress[] AddressList { get; set; }
member this.AddressList : System.Net.IPAddress[] with get, set
Public Property AddressList As IPAddress()
屬性值
IPAddress 型別的陣列,含有 IP 位址,解析在 Aliases 屬性中所含有的主機名稱。
範例
下列範例會 AddressList 使用 屬性來存取與 相關聯的 IPHostEntryIP位址。
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 : {0}", 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 : {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 );
}
}
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);
}
}
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