■ NetworkInterface 클래스 : GetAllNetworkInterfaces 정적 메소드를 사용해 MAC 주소 구하기

------------------------------------------------------------------------------------------------------------------------

using System.Net.NetworkInformation;

 

#region MAC 주소 구하기 - GetMACAddress()

 

/// <summary>

/// MAC 주소 구하기

/// </summary>

/// <returns>MAC 주소</returns>

public string GetMACAddress()

{

    NetworkInterface[] networkInterfaceArray = NetworkInterface.GetAllNetworkInterfaces();

 

    foreach(NetworkInterface networkInterface in networkInterfaceArray)

    {

        if(networkInterface.OperationalStatus == OperationalStatus.Up)

        {

            PhysicalAddress physicalAddress = networkInterface.GetPhysicalAddress();

 

            return physicalAddress.ToString();

        }

    }

 

    return null;

}

 

#endregion

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker