語言

IPv4InterfaceProperties 類別

定義

提供支援網際網路協定第4版(IPv4)的網路介面資訊。

public ref class IPv4InterfaceProperties abstract
public abstract class IPv4InterfaceProperties
type IPv4InterfaceProperties = class
Public MustInherit Class IPv4InterfaceProperties
繼承
IPv4InterfaceProperties

範例

以下程式碼範例會取得一個 GetIPv4Properties 物件並顯示其資料。

public static void DisplayIPv4NetworkInterfaces()
{
    NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
    IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
    Console.WriteLine("IPv4 interface information for {0}.{1}",
       properties.HostName, properties.DomainName);
    Console.WriteLine();

    foreach (NetworkInterface adapter in nics)
    {
        // Only display informatin for interfaces that support IPv4.
        if (!adapter.Supports(NetworkInterfaceComponent.IPv4))
        {
            continue;
        }
        Console.WriteLine(adapter.Description);
        // Underline the description.
        Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length,'='));
        IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
        // Try to get the IPv4 interface properties.
        IPv4InterfaceProperties p = adapterProperties.GetIPv4Properties();

        // Display the IPv4 specific data.
        Console.WriteLine("  Index ............................. : {0}", p.Index);
        Console.WriteLine("  MTU ............................... : {0}", p.Mtu);
        Console.WriteLine("  APIPA active....................... : {0}",
            p.IsAutomaticPrivateAddressingActive);
        Console.WriteLine("  APIPA enabled...................... : {0}",
            p.IsAutomaticPrivateAddressingEnabled);
        Console.WriteLine("  Forwarding enabled................. : {0}",
            p.IsForwardingEnabled);
        Console.WriteLine("  Uses WINS ......................... : {0}",
            p.UsesWins);
        Console.WriteLine();
    }
}
Public Shared Sub DisplayIPv4NetworkInterfaces() 
    Dim nics As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
    Dim properties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
    Console.WriteLine("IPv4 interface information for {0}.{1}", properties.HostName, properties.DomainName)
    
    Dim adapter As NetworkInterface
    For Each adapter In  nics
        ' Only display informatin for interfaces that support IPv4.
        If adapter.Supports(NetworkInterfaceComponent.IPv4) = False Then
            GoTo ContinueForEach1
        End If
        Console.WriteLine()
        Console.WriteLine(adapter.Description)
        ' Underline the description.
        Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length, "="c))
        Dim adapterProperties As IPInterfaceProperties = adapter.GetIPProperties()
        ' Try to get the IPv4 interface properties.
        Dim p As IPv4InterfaceProperties = adapterProperties.GetIPv4Properties()

        ' Display the IPv4 specific data.
        Console.WriteLine("  Index ............................. : {0}", p.Index)
        Console.WriteLine("  MTU ............................... : {0}", p.Mtu)
        Console.WriteLine("  APIPA active....................... : {0}", p.IsAutomaticPrivateAddressingActive)
        Console.WriteLine("  APIPA enabled...................... : {0}", p.IsAutomaticPrivateAddressingEnabled)
        Console.WriteLine("  Forwarding enabled................. : {0}", p.IsForwardingEnabled)
        Console.WriteLine("  Uses WINS ......................... : {0}", p.UsesWins)
    ContinueForEach1:
    Next adapter

End Sub

備註

此類別提供支援 IPv4 的網路介面的設定與位址資訊存取。 你不會建立這個類別的實例;它們會被方法回傳 GetIPv4Properties 。

關於 IPV6 屬性,請參見 GetIPv6Properties。

建構函式

名稱 Description
IPv4InterfaceProperties()

初始化 IPv4InterfaceProperties 類別的新執行個體。

屬性

名稱 Description
Index

取得與網際網路協定版本4(IPv4)位址相關的網路介面索引。

IsAutomaticPrivateAddressingActive

會獲得 Boolean 一個值,指示此介面是否具有自動私有 IP 位址(APIPA)位址。

IsAutomaticPrivateAddressingEnabled

會獲得 Boolean 一個值,指示此介面是否啟用自動私有 IP 位址(APIPA)。

IsDhcpEnabled

會獲得 Boolean 一個值,表示介面是否被設定為使用動態主機配置協定(DHCP)伺服器來取得 IP 位址。

IsForwardingEnabled

會獲得 Boolean 一個值,表示此介面是否能轉發(路由)封包。

Mtu

取得此網路介面的最大傳輸單元(MTU)。

UsesWins

會獲得一個 Boolean 值,表示介面是否使用Windows網際網路名稱服務(WINS)。

方法

名稱 Description
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type。

(繼承來源 Object)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於