Add Default aspx page for design purpose.
Default2.aspx
Default2.aspx.cs
(Write the below code in to code behind page or .cs file)
using System.Xml.Linq;
using System.Windows.Forms;
using System.Net.NetworkInformation;
public partial class Default2 :
System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
}
protected void
Button1_Click(object sender, EventArgs e)
{
//get all network interfaces
NetworkInterface[] netinterface = NetworkInterface.GetAllNetworkInterfaces();
//display the physical address of the first network
interface in the array,
//which should correspond to our mac address
Label1.Text = netinterface[0].GetPhysicalAddress().ToString();
}
Descriptions:
Let’s review what this code is
actually doing. First, we create an array of NetworkInterface objects and then
populate that using the GetAllNetworkInterfaces method. Then, we display the
physical or MAC address of the first NetworkInterface in the array which will
correspond to your MAC address. Depending on your hardware you may want to use
a different index of the array, however this will suffice for most machines.
Output: