Rupesh Kahane

Rupesh Kahane

  • 102
  • 19.1k
  • 4.2m

How to get mac address & Serial Number who is access URL MVC

May 13 2020 7:27 AM
I have an MVC application contains 1 controller & Index action method.
 
I have two different methods to get all MAC addresses & Serial Number of laptop / computer.
 
When I publish or host my code on XXX server & tries to access the Index method then it stores the information of all mac addresses & serial number Who is accessing the that page.
 
But what happends my code is always runs in the IIS of server so it stores the all details about that servers only, 
not about my clients MAC address & Serial Number. 
 
Suggest me something I can track all clients / users / visitors mac address those who are accessing the page.
 
Below is my code
 
  1.  public class HomeController : Controller  
  2.     {  
  3.           
  4.         public ActionResult Index()  
  5.         {  
  6.             try  
  7.             {  
  8.                   var allMacAddresses = getAllMacAddress();  
  9.                   var serialNo = getSerialNumber();  
  10.                   File.AppendAllText("myfilePath", allMacAddresses  + " " + serialNo  + Environment.NewLine);  
  11.             }  
  12.              catch (Exception)  
  13.             {  
  14.                 throw;  
  15.             }  
  16.             return View();  
  17.       }  

  18.       public static string getAllMacAddress()  
  19.         {  
  20.             NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();  
  21.             String sMacAddress = string.Empty;  
  22.             foreach (NetworkInterface adapter in nics)  
  23.             {                  
  24.                 if (adapter != null)  
  25.                 {  
  26.                     IPInterfaceProperties properties = adapter.GetIPProperties();  
  27.                     if (sMacAddress == string.Empty)  
  28.                     {  
  29.                         sMacAddress = adapter.Name + " : " + adapter.GetPhysicalAddress().ToString();  
  30.                     }  
  31.                     else  
  32.                     {                                            sMacAddress = sMacAddress + " , " + adapter.Name + " : " + adapter.GetPhysicalAddress().ToString();  
  33.                     }                        
  34.                 }  
  35.             }  
  36.             return sMacAddress;  
  37.         }    
  38.   
  39.        public static string getSerialNumber()  
  40.         {  
  41.             Process process = new Process();  
  42.             ProcessStartInfo startInfo = new ProcessStartInfo();  
  43.             startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;  
  44.             startInfo.FileName = "CMD.exe";  
  45.             startInfo.Arguments = "/C wmic bios get serialnumber";    
  46.             process.StartInfo = startInfo;  
  47.             process.StartInfo.UseShellExecute = false;  
  48.             process.StartInfo.RedirectStandardOutput = true;  
  49.             process.Start();  
  50.             process.WaitForExit();  
  51.             string output = process.StandardOutput.ReadToEnd();  
  52.             return output;  
  53.         }    
  54. }  
 In above code to get serial number I am using command prompt i.e. cmd.exe so it always run on the server.
 
 I would like to execute that command it on clients / users laptop who is accessing the page  
 
Is their any other way so I can get the information? please suggest  
 
 

Answers (2)