NetworkInterface Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menyediakan informasi konfigurasi dan statistik untuk antarmuka jaringan.
public ref class NetworkInterface abstract sealed
public ref class NetworkInterface abstract
public static class NetworkInterface
public abstract class NetworkInterface
type NetworkInterface = class
Public Class NetworkInterface
Public MustInherit Class NetworkInterface
- Warisan
-
NetworkInterface
Contoh
Contoh kode berikut menampilkan informasi tentang antarmuka.
void ShowNetworkInterfaces()
{
IPGlobalProperties ^ computerProperties = IPGlobalProperties::GetIPGlobalProperties();
array<NetworkInterface^>^nics = NetworkInterface::GetAllNetworkInterfaces();
Console::WriteLine( "Interface information for {0}.{1} ", computerProperties->HostName, computerProperties->DomainName );
if ( nics == nullptr || nics->Length < 1 )
{
Console::WriteLine( " No network interfaces found." );
return;
}
Console::WriteLine( " Number of interfaces .................... : {0}", nics->Length );
System::Collections::IEnumerator^ myEnum4 = nics->GetEnumerator();
while ( myEnum4->MoveNext() )
{
NetworkInterface ^ adapter = safe_cast<NetworkInterface ^>(myEnum4->Current);
IPInterfaceProperties ^ properties = adapter->GetIPProperties();
Console::WriteLine();
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( " Operational status ...................... : {0}",
adapter->OperationalStatus );
String^ versions = "";
// Create a display string for the supported IP versions.
if ( adapter->Supports( NetworkInterfaceComponent::IPv4 ) )
{
versions = "IPv4";
}
if ( adapter->Supports( NetworkInterfaceComponent::IPv6 ) )
{
if ( versions->Length > 0 )
{
versions = String::Concat( versions, " " );
}
versions = String::Concat( versions, "IPv6" );
}
Console::WriteLine( " IP version .............................. : {0}",
versions );
ShowIPAddresses( properties );
// The following information is not useful for loopback adapters.
if ( adapter->NetworkInterfaceType == NetworkInterfaceType::Loopback )
{
continue;
}
Console::WriteLine( " DNS suffix .............................. : {0}",
properties->DnsSuffix );
String^ label;
if ( adapter->Supports( NetworkInterfaceComponent::IPv4 ) )
{
IPv4InterfaceProperties ^ ipv4 = properties->GetIPv4Properties();
Console::WriteLine( " MTU...................................... : {0}",
ipv4->Mtu );
if ( ipv4->UsesWins )
{
IPAddressCollection ^ winsServers = properties->WinsServersAddresses;
if ( winsServers->Count > 0 )
{
label = " WINS Servers ............................ :";
ShowIPAddresses( label, winsServers );
}
}
}
Console::WriteLine( " DNS enabled ............................. : {0}",
properties->IsDnsEnabled );
Console::WriteLine( " Dynamically configured DNS .............. : {0}",
properties->IsDynamicDnsEnabled );
Console::WriteLine( " Receive Only ............................ : {0}",
adapter->IsReceiveOnly );
Console::WriteLine( " Multicast ............................... : {0}",
adapter->SupportsMulticast );
ShowInterfaceStatistics( adapter );
Console::WriteLine();
}
}
public static void ShowNetworkInterfaces()
{
IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
Console.WriteLine("Interface information for {0}.{1} ",
computerProperties.HostName, computerProperties.DomainName);
if (nics == null || nics.Length < 1)
{
Console.WriteLine(" No network interfaces found.");
return;
}
Console.WriteLine(" Number of interfaces .................... : {0}", nics.Length);
foreach (NetworkInterface adapter in nics)
{
IPInterfaceProperties properties = adapter.GetIPProperties();
Console.WriteLine();
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(" Operational status ...................... : {0}",
adapter.OperationalStatus);
string versions ="";
// Create a display string for the supported IP versions.
if (adapter.Supports(NetworkInterfaceComponent.IPv4))
{
versions = "IPv4";
}
if (adapter.Supports(NetworkInterfaceComponent.IPv6))
{
if (versions.Length > 0)
{
versions += " ";
}
versions += "IPv6";
}
Console.WriteLine(" IP version .............................. : {0}", versions);
ShowIPAddresses(properties);
// The following information is not useful for loopback adapters.
if (adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback)
{
continue;
}
Console.WriteLine(" DNS suffix .............................. : {0}",
properties.DnsSuffix);
string label;
if (adapter.Supports(NetworkInterfaceComponent.IPv4))
{
IPv4InterfaceProperties ipv4 = properties.GetIPv4Properties();
Console.WriteLine(" MTU...................................... : {0}", ipv4.Mtu);
if (ipv4.UsesWins)
{
IPAddressCollection winsServers = properties.WinsServersAddresses;
if (winsServers.Count > 0)
{
label = " WINS Servers ............................ :";
ShowIPAddresses(label, winsServers);
}
}
}
Console.WriteLine(" DNS enabled ............................. : {0}",
properties.IsDnsEnabled);
Console.WriteLine(" Dynamically configured DNS .............. : {0}",
properties.IsDynamicDnsEnabled);
Console.WriteLine(" Receive Only ............................ : {0}",
adapter.IsReceiveOnly);
Console.WriteLine(" Multicast ............................... : {0}",
adapter.SupportsMulticast);
ShowInterfaceStatistics(adapter);
Console.WriteLine();
}
}
Keterangan
Kelas ini merangkum data untuk antarmuka jaringan, juga dikenal sebagai adaptor, di komputer lokal. Anda tidak membuat instans kelas ini; GetAllNetworkInterfaces metode mengembalikan array yang berisi satu instans kelas ini untuk setiap antarmuka jaringan di komputer lokal.
Konstruktor
NetworkInterface() |
Menginisialisasi instans baru kelas NetworkInterface. |
Properti
Description |
Mendapatkan deskripsi antarmuka. |
Id |
Mendapatkan pengidentifikasi adaptor jaringan. |
IPv6LoopbackInterfaceIndex |
Mendapatkan indeks antarmuka loopback IPv6. |
IsReceiveOnly |
Boolean Mendapatkan nilai yang menunjukkan apakah antarmuka jaringan diatur ke hanya menerima paket data. |
LoopbackInterfaceIndex |
Mendapatkan indeks antarmuka loopback IPv4. |
Name |
Mendapatkan nama adaptor jaringan. |
NetworkInterfaceType |
Mendapatkan jenis antarmuka. |
OperationalStatus |
Mendapatkan status operasional koneksi jaringan saat ini. |
Speed |
Mendapatkan kecepatan antarmuka jaringan. |
SupportsMulticast |
Boolean Mendapatkan nilai yang menunjukkan apakah antarmuka jaringan diaktifkan untuk menerima paket multicast. |
Metode
GetAllNetworkInterfaces() |
Mengembalikan objek yang menjelaskan antarmuka jaringan di komputer lokal. |
GetIPProperties() |
Mengembalikan objek yang menjelaskan konfigurasi antarmuka jaringan ini. |
GetIPStatistics() |
Mendapatkan statistik IP untuk instans ini NetworkInterface . |
GetIPv4Statistics() |
Mendapatkan statistik IPv4 untuk instans ini NetworkInterface . |
GetIsNetworkAvailable() |
Menunjukkan apakah ada koneksi jaringan yang tersedia. |
GetPhysicalAddress() |
Mengembalikan Media Access Control (MAC) atau alamat fisik untuk adaptor ini. |
Supports(NetworkInterfaceComponent) |
Boolean Mendapatkan nilai yang menunjukkan apakah antarmuka mendukung protokol yang ditentukan. |