Click here to Skip to main content
15,885,694 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am writing a Node.Js server, I uploaded it to Heroku,
I'm using IPs to make a temporary cart for each user (device),
I want to distinct also every device in the same network,
I mean I want to make a cart for every user, (also in the same IP)
I tried to use mac address but it's getting the host mac address(the Heroku mac address).
I need the local device mac address

What I have tried:

let ip;
let ipAddr = req.headers['x-forwarded-for'];
if (ipAddr) {
  var list = ipAddr.split(",");
  ip = list[list.length - 1];
} else {
  ip = req.socket.remoteAddress;
}


const ipFoundOrNot = await IP.findOne({ postIP: ip });


IP is my Model Schema, I want to find also a computer name or something else better to distinguish also users in the same network,
I mean by that something like this...
let computerName = process.env.COMPUTERNAME;

const ipFoundOrNot = await IP.findOne({ postIP: ip,computerName:computerName });


But when I do process.env.COMPUTERNAME I get undefined in node js in heroku...
I also tried to get the device mac address, it works fine in localhost, But when I apply it to heroku, it's getting the mac address of the heroku server..
Posted
Updated 10-Jun-21 22:34pm
v3
Comments
[no name] 10-Jun-21 13:57pm    
Use the device's MAC address.
Ayman Ghandour 10-Jun-21 17:45pm    
when I am using mac address on localhost it's working but when I'm using mac address on Heroku it gets mac address of the server.
can you please give me an example of how to get local mac address when I am in Heroku host
[no name] 10-Jun-21 18:18pm    
Google.

https://networkinterview.com/ways-to-find-mac-address-of-remote-computers/
Ayman Ghandour 10-Jun-21 18:37pm    
How that should help me...
I know my mac address...
I don't need it...
I want a node.js gets the device mac address not mine...
When a user open the site I want to make an temporary cart for him,
So when he add products it's added to his temp cart,
I need his mac address so I can distinguish his device from another device in his network... my code up is to distinguish every user and associate a temp cart for him...
I wanna get local mac address when I am in Heroku node.js,
when I am getting the mac address in node.js in Heroku it gets the server mac address, which I don't want, I wanna the local mac address of the user visiting my site, (the device mac address)
[no name] 10-Jun-21 20:01pm    
You didn't try any of the methods (and learn something new). You didn't google the keywords for something more to your liking. You don't know the difference between local and remote. You have me confused with someone who spoon feeds.

1 solution

Don't try to use the IP address or the MAC address. The public IP address will be shared by multiple users. The local IP address is meaningless beyond the user's local network, and will be duplicated on other local networks.

Instead, store a unique identifier in a session variable or cookie to identify the user's cart.
 
Share this answer
 
Comments
[no name] 12-Jun-21 10:18am    
A "user" is not a "device".
Ayman Ghandour 13-Jun-21 0:27am    
Thank you all for your help, Every thing is working great I get the IP for every device, and every IP having its private temp cart, what I need is to distinguish every user in the same IP, what I need is to have both remote IP and local IP (192.168.0.1) or something else to have every user the cart private just for him not for his entire network (using just remote IP),
Can You Please tell me how to get the local IP address in node.js uploaded to Heroku,
I have been googling a whole week and can't find this solution...
So please if anyone can help me to distinguish a device in a network, I will be very thankful.
Richard Deeming 14-Jun-21 3:55am    
As Gerry said, a device is not a user.

Stop trying to extract meaningless information which isn't available to your code, and start using the correct tool for the job.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900