NetworkInterface.NetworkInterfaceType 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得介面類型。
public:
virtual property System::Net::NetworkInformation::NetworkInterfaceType NetworkInterfaceType { System::Net::NetworkInformation::NetworkInterfaceType get(); };
public:
abstract property System::Net::NetworkInformation::NetworkInterfaceType NetworkInterfaceType { System::Net::NetworkInformation::NetworkInterfaceType get(); };
public virtual System.Net.NetworkInformation.NetworkInterfaceType NetworkInterfaceType { get; }
public abstract System.Net.NetworkInformation.NetworkInterfaceType NetworkInterfaceType { get; }
member this.NetworkInterfaceType : System.Net.NetworkInformation.NetworkInterfaceType
Public Overridable ReadOnly Property NetworkInterfaceType As NetworkInterfaceType
Public MustOverride ReadOnly Property NetworkInterfaceType As NetworkInterfaceType
屬性值
NetworkInterfaceType 值,指定網路介面類型。
範例
下列範例會顯示本機計算機上所有介面的類型資訊。
void DisplayTypeAndAddress()
{
IPGlobalProperties ^ computerProperties = IPGlobalProperties::GetIPGlobalProperties();
array<NetworkInterface^>^nics = NetworkInterface::GetAllNetworkInterfaces();
Console::WriteLine( "Interface information for {0}.{1} ", computerProperties->HostName, computerProperties->DomainName );
System::Collections::IEnumerator^ myEnum27 = nics->GetEnumerator();
while ( myEnum27->MoveNext() )
{
NetworkInterface ^ adapter = safe_cast<NetworkInterface ^>(myEnum27->Current);
IPInterfaceProperties ^ properties = adapter->GetIPProperties();
Console::WriteLine( adapter->Description );
Console::WriteLine( String::Empty->PadLeft( adapter->Description->Length, '=' ) );
Console::WriteLine( " Interface type .......................... : {0}",
adapter->NetworkInterfaceType );
Console::WriteLine( " Physical Address ........................ : {0}",
adapter->GetPhysicalAddress() );
Console::WriteLine( " Is receive only.......................... : {0}",
adapter->IsReceiveOnly );
Console::WriteLine( " Multicast................................ : {0}",
adapter->SupportsMulticast );
}
}
public static void DisplayTypeAndAddress()
{
IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
Console.WriteLine("Interface information for {0}.{1} ",
computerProperties.HostName, computerProperties.DomainName);
foreach (NetworkInterface adapter in nics)
{
IPInterfaceProperties properties = adapter.GetIPProperties();
Console.WriteLine(adapter.Description);
Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length,'='));
Console.WriteLine(" Interface type .......................... : {0}", adapter.NetworkInterfaceType);
Console.WriteLine(" Physical Address ........................ : {0}",
adapter.GetPhysicalAddress().ToString());
Console.WriteLine(" Is receive only.......................... : {0}", adapter.IsReceiveOnly);
Console.WriteLine(" Multicast................................ : {0}", adapter.SupportsMulticast);
Console.WriteLine();
}
}
Public Shared Sub DisplayTypeAndAddress()
Dim computerProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
Dim nics As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
Console.WriteLine("Interface information for {0}.{1} ", computerProperties.HostName, computerProperties.DomainName)
Dim adapter As NetworkInterface
For Each adapter In nics
Dim properties As IPInterfaceProperties = adapter.GetIPProperties()
Console.WriteLine(adapter.Description)
Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length, "="c))
Console.WriteLine(" Interface type .......................... : {0}", adapter.NetworkInterfaceType)
Console.WriteLine(" Physical Address ........................ : {0}", adapter.GetPhysicalAddress().ToString())
Console.WriteLine(" Is receive only.......................... : {0}", adapter.IsReceiveOnly)
Console.WriteLine(" Multicast................................ : {0}", adapter.SupportsMulticast)
Next adapter
End Sub
備註
列舉檔中會詳細說明 System.Net.NetworkInformation.NetworkInterfaceType 介面類型。
基本上,這個屬性可以傳回列舉的任何成員 NetworkInterfaceType 。 它所傳回的特定值取決於基礎網路拓撲的運行時間條件。 這表示:
您無法事先判斷屬性針對特定網路傳回的值。
在實務上,在特定網路上可能無法使用完整的列舉值範圍。 例如,在 Gb 乙太網路上,屬性可能會傳 NetworkInterfaceType.Ethernet 回,而不是 NetworkInterfaceType.GigabitEthernet。