Share via


NetworkInterface.GetPhysicalAddress 메서드

정의

이 어댑터에 대한 MAC(Media Access Control) 또는 실제 주소를 반환합니다.

public:
 virtual System::Net::NetworkInformation::PhysicalAddress ^ GetPhysicalAddress();
public:
 abstract System::Net::NetworkInformation::PhysicalAddress ^ GetPhysicalAddress();
public virtual System.Net.NetworkInformation.PhysicalAddress GetPhysicalAddress ();
public abstract System.Net.NetworkInformation.PhysicalAddress GetPhysicalAddress ();
abstract member GetPhysicalAddress : unit -> System.Net.NetworkInformation.PhysicalAddress
override this.GetPhysicalAddress : unit -> System.Net.NetworkInformation.PhysicalAddress
abstract member GetPhysicalAddress : unit -> System.Net.NetworkInformation.PhysicalAddress
Public Overridable Function GetPhysicalAddress () As PhysicalAddress
Public MustOverride Function GetPhysicalAddress () As PhysicalAddress

반환

실제 주소가 들어 있는 PhysicalAddress 개체입니다.

예제

다음 코드 예제에서는 로컬 컴퓨터에 있는 모든 인터페이스의 실제 주소를 표시 합니다.

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

설명

이 메서드에서 반환된 개체에는 데이터 링크 계층에서 데이터를 전송하는 데 사용되는 미디어에 적합한 주소가 포함되어 있습니다. 예를 들어 이더넷 네트워크에서 이 메서드는 이더넷 하드웨어 주소를 반환합니다.

적용 대상