//Add the following Using
using System;
using System.IO;
// Add a webform in your web app and modify the code for Page_Load event as follows:
protected void Page_Load(object sender, EventArgs e)
{
string MyDomainPrefix = @"CONTOSO\\"; //replace CONTOSO with your network domain
string currentUserLoginName = Request.LogonUserIdentity.Name.Replace(MyDomain, string.Empty); // Get the current Windows authenticated user
string myCommandToRun = "/c nbtstat -a " + Request.UserHostName + @" >> " + AppDomain.CurrentDomain.BaseDirectory +
currentUserLoginName + ".txt"; // Command line to run, I am creating my text file in the web application folder on the server.
Note: nbtstat command does not work on my client machine with Windows 7.
//Execute the command
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = myCommandToRun;
process.Start();
process.WaitForExit();
//Start parsing the file created on disk
StreamReader sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + currentUserLoginName + ".txt");
string MyLine = null;
MyLine = sr.ReadToEnd();
string[] MyStrings = MyLine.Trim().Split('\n'); //Array of strings from text file split by the return char
foreach (string item in MyStrings)
{
if (item.Trim().Contains("MAC Address"))
{
//Get the MAC Address
Response.Write(item.ToString().Remove(0,item.IndexOf('=')+1).Trim());
}
}
}This code snipet retrieve the web application remote client MAC address and display it on a webform. Your web application (web site must use Windows authentication mode. This code works only if web server and the remote client machine are on the same domain (web app to be used internaly).