語言

IPInterfaceProperties.DhcpServerAddresses 屬性

定義

取得此介面的動態主機配置協定(DHCP)伺服器位址。

public:
 abstract property System::Net::NetworkInformation::IPAddressCollection ^ DhcpServerAddresses { System::Net::NetworkInformation::IPAddressCollection ^ get(); };
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("freebsd")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("osx")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public abstract System.Net.NetworkInformation.IPAddressCollection DhcpServerAddresses { get; }
public abstract System.Net.NetworkInformation.IPAddressCollection DhcpServerAddresses { get; }
[<System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("freebsd")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("osx")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
member this.DhcpServerAddresses : System.Net.NetworkInformation.IPAddressCollection
member this.DhcpServerAddresses : System.Net.NetworkInformation.IPAddressCollection
Public MustOverride ReadOnly Property DhcpServerAddresses As IPAddressCollection

屬性值

一個 IPAddressCollection 包含 DHCP 伺服器位址資訊的 Array,若找不到伺服器則是空陣列。

屬性

範例

以下程式碼範例顯示本地電腦網路介面的 DHCP 位址資訊。

public static void DisplayDhcpServerAddresses()
{
    Console.WriteLine("DHCP Servers");
    NetworkInterface[] adapters  = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface adapter in adapters)
    {

        IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
        IPAddressCollection addresses = adapterProperties.DhcpServerAddresses;
        if (addresses.Count >0)
        {
            Console.WriteLine(adapter.Description);
            foreach (IPAddress address in addresses)
            {
                Console.WriteLine("  Dhcp Address ............................ : {0}",
                    address.ToString());
            }
            Console.WriteLine();
        }
    }
}
Public Shared Sub DisplayDhcpServerAddresses() 
    Console.WriteLine("DHCP Servers")
    Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
    Dim adapter As NetworkInterface
    For Each adapter In  adapters
        
        Dim adapterProperties As IPInterfaceProperties = adapter.GetIPProperties()
        Dim addresses As IPAddressCollection = adapterProperties.DhcpServerAddresses
        If addresses.Count > 0 Then
            Console.WriteLine(adapter.Description)
            Dim address As IPAddress
            For Each address In  addresses
                Console.WriteLine("  Dhcp Address ............................ : {0}", address.ToString())
            Next address
            Console.WriteLine()
        End If
    Next adapter

End Sub

備註

動態主機設定協定(DHCP)允許電腦從 DHCP 伺服器取得網路位址,而非使用靜態(固定)網路位址。 DHCP 伺服器不會永久分配位址;取而代之的是,它暫時使用電腦可用的多個位址之一。

適用於