14

I have to get Mac Address of client's PC where my website is running. So how to get Mac Address of client's machine (not of the Server's Mac Address where website is hosted). I need script that is compatible with IE, Firefox, Safari and Chrome.

halfer
  • 19,824
  • 17
  • 99
  • 186
nirav patel
  • 465
  • 2
  • 6
  • 16
  • In the first place why do you want the MAC address? – Ramesh Mar 28 '12 at 09:03
  • I have scenario where some user are allowed from some fixed PC (for which MAC address entered by admin will match with system from where user try to logged in) , he/she will not able to logged in from other than those PC. – nirav patel Mar 28 '12 at 09:08
  • i have tried to getting mac address with javascript. But it is possible with IE only, not other browser. – nirav patel Mar 28 '12 at 09:09
  • @niravpatel you may not be able to read the mac even in IE, if it is being served from Server and mostly your security setting in IE will prohibit doing that. A web application security should not be relayed upon MAC address. Also, as we are fetching the MAC address using javascript user can still modify the logic and pass a fake MAC address which has access. – Ramesh Mar 28 '12 at 09:56
  • I don't think you can get MAC address of the client; say when it is in different subnet & thus communicates via a switch. If it is in same SUBNET, then only you can get its MAC address. Can someone confirm whether my understanding is true? – anishsane Oct 25 '12 at 13:29
  • did you figured that out? if yes please share how you get the client's mac address, I need to do the same – Alex Dec 04 '13 at 09:20

3 Answers3

8

The only way to achieve this is by using an applet or plugin which could for example be programmed in java (although java itself might not allow it according to Getting MAC address on a web page using a Java applet ), as javascript will naturally not disclose this kind of information. Lastly you could also find this information from the server side if it's on an internal network as is often done with semi-private wifi network landing pages.

Based on the comments below: As it's an internal network you can retrieve the mac address as follows on the asp.net side. You execute the following command arp -a which will return you a list of all ip addresses with associated mac addresses. Next using something along the lines of

Request.Servervariables("REMOTE_ADDR")

you should be able to find the users ip address which you can next match with the data you retrieved from the arp command and voila, you have your mac address for the current user.

Community
  • 1
  • 1
David Mulder
  • 26,123
  • 9
  • 51
  • 114
  • Hi David, Thanks for replying. Any way to get IP Address instead of MAC Address in same scenario. Where IP Configuration is DHCP(Dynamic IP).? – nirav patel Mar 28 '12 at 09:16
  • Do I understand correctly that this is on an internal network? (Because than there are a few options you have) – David Mulder Mar 28 '12 at 09:23
  • I have edited my answer above to reflect how you can find the mac address in that case. – David Mulder Mar 28 '12 at 10:02
  • I would still prefer windows authentication to restrict certain users instead of the machines in which they login. http://support.microsoft.com/kb/323176 – Ramesh Mar 28 '12 at 10:20
  • Hi David, thanks for good answer. But by that i have to run arp -a command in background with asp.net right? – nirav patel Mar 28 '12 at 10:20
  • Yes and the mac address lookup would need to happen in asp.net as well. (Btw, there might be an arp library or something along those lines in asp.net... but I wouldn't know about that) – David Mulder Mar 28 '12 at 11:03
7

I have scenario where some user are allowed from some fixed PC (for which MAC address entered by admin will match with system from where user try to logged in) , he/she will not able to logged in from other than those PC

To achieve the above the right way, you should be relying on Client certificates to perform the authentication. If a valid client certificate is not presented then the request will be denied.

You can find more information on Securing a website using client certificates @ http://support.microsoft.com/kb/315588

If the users are in internal network, preferred way to authenticate them is using the Integrated windows authentication as described http://support.microsoft.com/kb/323176 and authorization will be based on a Access control list

Ramesh
  • 13,043
  • 3
  • 52
  • 88
  • Hi Ramesh....Thanks for replying with good answer. By using above technique , i have to installed client certificate in each PC from where client can access the website, right? – nirav patel Mar 28 '12 at 10:18
  • Yes. You need to install the client certificates from which you need to access. This will help you even if tomorrow the network hardware changes. But look at Integrated authentication if its an internal network. – Ramesh Mar 28 '12 at 10:24
  • Client Certificate is very good idea for internal authentication, but even if my requirement is to achieve more security. like particular one user can access particular two to three pc not all pc where client certificate is installed. as well other users who are not able o logged in to that pc that is consumed by first user and have client certificate installed. – nirav patel Mar 28 '12 at 10:54
  • If you need a machine based authorization (as you were doing with Mac) you can go for client certificates. if you need to authorize user based on the logon credentials you need to go for Integrated authentication. – Ramesh Mar 28 '12 at 10:58
  • hi ramesh, i have to achieved both partially. that would be possible? how? – nirav patel Mar 28 '12 at 11:01
  • By using integrated authentication, it would by default take the currently logged in user. So, if the user has allowed to login into the machine he can access the site. If the user is not allowed to log into the machine, it needs to be restricted by the network administrator by configuring in Active directory and Group policy. – Ramesh Mar 28 '12 at 11:05
2

Sounds like this is an internal network.

Another method is that by using mac address the dhcp server can assign particular ip ranges. you can then check for that ip range in your server code. There is not a way to get mac address in javascript, but you can get the ip easily. Also perhaps your dhcp server can publish mac address ip address tables for your web server to use via an api or something - not sure on that but may be worth looking into.

Symeon Breen
  • 1,531
  • 11
  • 25