PhysicalAddress Klasa

Definicja

Udostępnia adres Access Control multimediów (MAC) dla interfejsu sieciowego (karty).

public ref class PhysicalAddress
public class PhysicalAddress
type PhysicalAddress = class
Public Class PhysicalAddress
Dziedziczenie
PhysicalAddress

Przykłady

Poniższy przykład kodu przedstawia fizyczne adresy wszystkich interfejsów na komputerze lokalnym.

void ShowNetworkInterfaces()
{
   IPGlobalProperties^ computerProperties = IPGlobalProperties::GetIPGlobalProperties();
   array<NetworkInterface^>^nics = NetworkInterface::GetAllNetworkInterfaces();
   Console::WriteLine( L"Interface information for {0}.{1}     ", computerProperties->HostName, computerProperties->DomainName );
   if ( nics == nullptr || nics->Length < 1 )
   {
      Console::WriteLine( L"  No network interfaces found." );
      return;
   }

   Console::WriteLine( L"  Number of interfaces .................... : {0}", (nics->Length).ToString() );
   IEnumerator^ myEnum1 = nics->GetEnumerator();
   while ( myEnum1->MoveNext() )
   {
      NetworkInterface^ adapter = safe_cast<NetworkInterface^>(myEnum1->Current);
      IPInterfaceProperties^ properties = adapter->GetIPProperties();
      Console::WriteLine();
      Console::WriteLine( adapter->Description );
      Console::WriteLine( String::Empty->PadLeft( adapter->Description->Length, '=' ) );
      Console::WriteLine( L"  Interface type .......................... : {0}", adapter->NetworkInterfaceType );
      Console::Write( L"  Physical address ........................ : " );
      PhysicalAddress^ address = adapter->GetPhysicalAddress();
      array<Byte>^bytes = address->GetAddressBytes();
      for ( int i = 0; i < bytes->Length; i++ )
      {
         
         // Display the physical address in hexadecimal.
         Console::Write( L"{0}", bytes[ i ].ToString( L"X2" ) );
         
         // Insert a hyphen after each byte, unless we are at the end of the 
         // address.
         if ( i != bytes->Length - 1 )
         {
            Console::Write( L"-" );
         }

      }
      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(); //  .GetIPInterfaceProperties();
        Console.WriteLine();
        Console.WriteLine(adapter.Description);
        Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length, '='));
        Console.WriteLine("  Interface type .......................... : {0}", adapter.NetworkInterfaceType);
        Console.Write("  Physical address ........................ : ");
        PhysicalAddress address = adapter.GetPhysicalAddress();
        byte[] bytes = address.GetAddressBytes();
        for (int i = 0; i < bytes.Length; i++)
        {
            // Display the physical address in hexadecimal.
            Console.Write("{0}", bytes[i].ToString("X2"));
            // Insert a hyphen after each byte, unless we're at the end of the address.
            if (i != bytes.Length - 1)
            {
                Console.Write("-");
            }
        }
        Console.WriteLine();
    }
}

Uwagi

Adres MAC lub adres fizyczny to adres sprzętowy, który jednoznacznie identyfikuje każdy węzeł, taki jak komputer lub drukarka, w sieci.

Wystąpienia tej klasy są zwracane przez metodę NetworkInterface.GetPhysicalAddress .

Konstruktory

PhysicalAddress(Byte[])

Inicjuje nowe wystąpienie klasy PhysicalAddress.

Pola

None

Zwraca nowe PhysicalAddress wystąpienie z adresem o zerowej długości. To pole jest tylko do odczytu.

Metody

Equals(Object)

Porównuje dwa PhysicalAddress wystąpienia.

GetAddressBytes()

Zwraca adres bieżącego wystąpienia.

GetHashCode()

Zwraca wartość skrótu adresu fizycznego.

GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
Parse(ReadOnlySpan<Char>)

Analizuje określony zakres i przechowuje jego zawartość jako bajty adresów PhysicalAddress zwracane przez tę metodę.

Parse(String)

Analizuje określoną String zawartość i przechowuje jej zawartość jako bajty adresów PhysicalAddress zwracane przez tę metodę.

ToString()

Zwraca reprezentację String adresu tego wystąpienia.

TryParse(ReadOnlySpan<Char>, PhysicalAddress)

Próbuje przekonwertować reprezentację zakresu adresu sprzętowego na PhysicalAddress wystąpienie. Wartość zwracana wskazuje, czy konwersja zakończyła się pomyślnie.

TryParse(String, PhysicalAddress)

Próbuje przekonwertować ciąg reprezentujący adres sprzętowy PhysicalAddress na wystąpienie. Wartość zwracana wskazuje, czy konwersja zakończyła się pomyślnie.

Dotyczy