-1

I have a webserver and the backend is written in nodejs. I am trying to get the mac address of each device accessing my website. I am using the getmac package and here is my code

Const getmac = require('getmac')
Const device = getmac.default()
Console.log(device)

Even though i am accessing my website from two totally different devices. I get the same mac address. Can some clarify. By the way i checked mac address of each device in my modem config page and there are different

Ahmed
  • 1,229
  • 2
  • 20
  • 45
  • 1
    Soft duplicate of [How can I get a MAC address from an HTTP request?](https://stackoverflow.com/questions/3309122/how-can-i-get-a-mac-address-from-an-http-request) - TL;DR - unless the network between your devices is setup in the same network segment, your devices' MAC addresses aren't transmitted through HTTP. The library you're using explicitly calls out in its README that it will not function properly in "*web browsers / on the client-side...*". – esqew Mar 07 '21 at 19:59
  • (2/2) It could debatably be [somewhat of a security risk if sites were arbitrarily allowed to recieve this information](https://security.stackexchange.com/questions/67893/is-it-dangerous-to-post-my-mac-address-publicly) anyway. I can imagine if ad tracking companies had access to this information it would be much worse. – esqew Mar 07 '21 at 20:02

2 Answers2

2

I assume you are getting the mac address of the server the nodejs code is running on. It doesn't get the mac address of the client (browser).

The opening statement at https://www.npmjs.com/package/getmac:

This library will not run in web browsers / on the client-side / in webpack / in browserify / in angular / in react / in jQuery / in HTML. It will only run on Node.js environments, which the web browser is not.

Brettski
  • 19,351
  • 15
  • 74
  • 97
0

The getmac package only gets the mac address of the listening machine.

You are getting the same mac addresses because it has nothing to do with the mac addresses of the devices you are using to visit the server. It can ONLY get the server's own mac address.

enter image description here

cseitz
  • 1,116
  • 4
  • 16