0

I am working on a project using mongodb, express and nodejs to build an intranet based webapp. The goal of the project is to acquire a user mac address upon authentication and run a remote ssh. I am however finding it difficult to get the remote pc mac address. The clients and server are meant to be on the same local subnet. I tried using the node getmac module, but apparently it only gives host server's mac,

var macAddress = require('getmac');
require('getmac').getMac(function(err, macAddress){
if (err)  throw err
console.log(macAddress)
});

I also tried the macfromip module but with that you have to predefine the host IP to get the mac of the remote computer.

var macfromip = require('macfromip');
macfromip.getMac('192.168.1.100', function(err, data){
    if(err){
        console.log(err);
    }
    console.log(data);

});

Is there any other way i could get the user's mac address?

Salman S
  • 47
  • 1
  • 15

2 Answers2

1

Doesn't seem like you can get the MAC address from a IP.
The documentation of getMac doesn't have anything related to .getMac('192.168.1.100')

A way I would see this working is having a database with the IPs and their MAC address.
This would require something to save those each MAC address in the database. Probably a script running on startup on each computer.


Someone asked this question on security.stackexchange.com. As it is on the same network, if you use the command ping on the command line, the MAC address of that IP would be registered on ARP list.

ping your_ip_address

And with this you should be able to get the MAC Addresses:

arp -a

With that in mind, I found these 2 nodejs packages that might interest you: https://www.npmjs.com/package/ping and https://www.npmjs.com/package/node-arp

André
  • 4,417
  • 4
  • 29
  • 56
  • thanks for your response, however, like i mentioned, the getMac module only gives the mac address of the server, there is another npm module "macfromip" that gets the mac address of the predefined ip address and it works, however, clients might login from random machines and so their ip address would vary. – Wolobah Gbozee Mar 26 '18 at 09:40
  • I don't see a issue then. What do you except it to do if one user logs in from random machines? – André Mar 26 '18 at 09:42
  • i need to get the mac address of the the particular machine the user login from, i would have use the macfromip if i knew already the the source machine of the user login, but since user might login from different pcs on the network i want to associate mac address with logins – Wolobah Gbozee Mar 26 '18 at 09:47
  • But: `Login > HTTP Request > IP > MAC` for each login for each computer. You could on login ask if this is a permanent computer, and you can only have one permanent computer. And save that MAC address to the database – André Mar 26 '18 at 09:53
0

I imagine you would have to do this client side and pass it back.

By the sounds of this SO answer you can't do it easily in in Javascript but the answer suggests:

  • Using Java (with a signed applet)
  • Using signed Javascript, which in FF (and Mozilla in general) gets higher privileges than normal JS (but it is fairly complicated to set up)
Stretch0
  • 8,362
  • 13
  • 71
  • 133