-1

I am developing software using ASP.NET C# in which I want to allow only users from specific machines to login to the software, i.e I want a user to login from his office computer but he shouldn't be allowed to login to the website from his home computer or any other computer. To achieve this, I tried to get the mac address of the client computer using code in C# but this code is only returning the mac address of the server. Also, I read on the internet that getting mac address of client computers is inefficient. So I want to know if there any better ways to identify the client computer from the server. I'm using the following code.

string macAddresses = "";

foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
    if (nic.OperationalStatus == OperationalStatus.Up)
    {
        macAddresses += nic.GetPhysicalAddress().ToString();
        break;
    }
}
Response.Write( macAddresses);
Andrew Sula
  • 939
  • 8
  • 24
user3807218
  • 47
  • 1
  • 6
  • `getting mac address of client computer is inefficient` You can't get it unless client passes it explicitely.. – L.B Aug 12 '14 at 06:36
  • I am not sure whether you will get any client machine details. It is against security, so I think it will not be allowed. – Mahesh KP Aug 12 '14 at 06:39
  • Everyone wants to get "identification of client computer" that runs the browser... but no one is also willing to provide such information when its they own computer to be "identified". Till people are happy to be tracked everywhere you'll have hard time getting this information as security measures restrict browser's access to such information. – Alexei Levenkov Aug 12 '14 at 06:43
  • is it possible to identify cient on ip address of computer or office as I want client to login only inside office premises or using only office computer. – user3807218 Aug 12 '14 at 07:30
  • Yes IP is possible. See the closing reason... – L.B Aug 12 '14 at 08:44

2 Answers2

0

There is no practical way to enforce this at the application level. Even if the browser were kind (or stupid) enough to provide that information to you, you can't rely on it, since the user can easily fake it. One possibility to solve this is at the firewall level.

EDIT: Also don't ever rely on the MAC address for security in any way. You don't need to be a great hacker to be able to claim any physical MAC address you want - it's particularly easy with virtual machines.

chris
  • 2,541
  • 1
  • 23
  • 40
-1

Try fetching the Motherboard Serial of the PC, which is unique and condition it in running the application.

-- you can make use of IP address and MAC Address as well, but these dont respond well in case the PC is offline.

Best try is to make use of the Mother board Serial, follow the example:

using System.Management;

and in button click event next code:)

private void button1_Click(object sender, EventArgs e)
{
    ManagementObjectSearcher MOS = new ManagementObjectSearcher("Select * From        Win32_BaseBoard");
    foreach (ManagementObject getserial in MOS.Get())
    {
        label1.Text="Your motherboard serial is : "+ getserial["SerialNumber"].ToString();
    }

}

If this is helpful, mark as answer -Kaushik

  • While it may be helpful to someone this post is not related to questions as one can't use such code to run on *client* computer that user uses to browse the ASP.Net site. – Alexei Levenkov Aug 12 '14 at 06:41