Thursday 6 June 2013

Find System MAC Address using C#

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write(GetMACAddress());
}

public string GetMACAddress()
{
        NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();        
        foreach (NetworkInterface adapter in nics)
        {
             if (sMacAddress == String.Empty)  // only return MAC Address from first card  
             {
                   IPInterfaceProperties properties = adapter.GetIPProperties();
                   return adapter.GetPhysicalAddress().ToString();
              }
        }
        return String.Empty;
}

1 comments:

Unknown said...

I was searching for this code to as in an interview i was asked this question . Can you change the MAC Address of your network device using C# language ?
Thanks for sharing

Regards
Silvester Norman

Change Mac Address

Post a Comment