Asp.Net :
Host Name : <asp:Label ID="lblHostName" runat="server" ></asp:Label><br />
IP Address : <asp:Label ID="lblIPAddress" runat="server" ></asp:Label><br />
MAC Address : <asp:Label ID="lblMacAddress" runat="server" ></asp:Label><br />
C# :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.NetworkInformation;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Get_IP();
Get_MAC();
}
protected void Get_IP()
{
string HostName = Dns.GetHostName(); // Retrive the Name of HOST
lblHostName.Text = HostName;
string IPAddress = Dns.GetHostByName(HostName).AddressList[0].ToString(); // Get the IP
lblIPAddress.Text = IPAddress;
}
protected void Get_MAC()
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
String sMacAddress = string.Empty;
foreach (NetworkInterface adapter in nics)
{
if (sMacAddress == String.Empty)// only return MAC Address from first card
{
IPInterfaceProperties properties = adapter.GetIPProperties();
sMacAddress = adapter.GetPhysicalAddress().ToString(); //get mac address
}
}
lblMacAddress.Text = sMacAddress;
}
}