IPInterfaceProperties.DnsAddresses 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得這個介面的網域名稱系統 (DNS) 伺服器位址。
public:
abstract property System::Net::NetworkInformation::IPAddressCollection ^ DnsAddresses { System::Net::NetworkInformation::IPAddressCollection ^ get(); };
public abstract System.Net.NetworkInformation.IPAddressCollection DnsAddresses { get; }
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
public abstract System.Net.NetworkInformation.IPAddressCollection DnsAddresses { get; }
member this.DnsAddresses : System.Net.NetworkInformation.IPAddressCollection
[<System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
member this.DnsAddresses : System.Net.NetworkInformation.IPAddressCollection
Public MustOverride ReadOnly Property DnsAddresses As IPAddressCollection
屬性值
IPAddressCollection,包含 DNS 伺服器位址。
- 屬性
範例
下列程式代碼範例會顯示本機電腦上的網路介面 DNS 位址。
void DisplayDnsAddresses()
{
array<NetworkInterface^>^adapters = NetworkInterface::GetAllNetworkInterfaces();
System::Collections::IEnumerator^ myEnum11 = adapters->GetEnumerator();
while ( myEnum11->MoveNext() )
{
NetworkInterface ^ adapter = safe_cast<NetworkInterface ^>(myEnum11->Current);
IPInterfaceProperties ^ adapterProperties = adapter->GetIPProperties();
IPAddressCollection ^ dnsServers = adapterProperties->DnsAddresses;
if ( dnsServers->Count > 0 )
{
Console::WriteLine( adapter->Description );
System::Collections::IEnumerator^ myEnum12 = dnsServers->GetEnumerator();
while ( myEnum12->MoveNext() )
{
IPAddress ^ dns = safe_cast<IPAddress ^>(myEnum12->Current);
Console::WriteLine( " DNS Servers ............................. : {0}",
dns->ToString());
}
}
}
}
public static void DisplayDnsAddresses()
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
IPAddressCollection dnsServers = adapterProperties.DnsAddresses;
if (dnsServers.Count > 0)
{
Console.WriteLine(adapter.Description);
foreach (IPAddress dns in dnsServers)
{
Console.WriteLine(" DNS Servers ............................. : {0}",
dns.ToString());
}
Console.WriteLine();
}
}
}
Public Shared Sub DisplayDnsAddresses()
Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
Dim adapter As NetworkInterface
For Each adapter In adapters
Dim adapterProperties As IPInterfaceProperties = adapter.GetIPProperties()
Dim dnsServers As IPAddressCollection = adapterProperties.DnsAddresses
If dnsServers.Count > 0 Then
Console.WriteLine(adapter.Description)
Dim dns As IPAddress
For Each dns In dnsServers
Console.WriteLine(" DNS Servers ............................. : {0}",dns.ToString() )
Next dns
End If
Next adapter
End Sub
備註
DNS 是階層式命名系統,用來將主機名對應至IP位址。