3

I'm running a simple node.js server that also gots a webinterface using express. Every time a clients goes on the website I'd like to find out who else from this clients network is connected.


I know that I can read out the localIP address of every client using some syntax like this.

 var ip = req.headers['x-forwarded-for'] || 
 req.connection.remoteAddress || 
 req.socket.remoteAddress ||
 (req.connection.socket ? req.connection.socket.remoteAddress : null);

... but how can I determine which clients are in the same network? (LAN)

I'm aware that the IP-address is nearly unnecessary/needless because of the currently unkwown Network ID - but how can I determine the networkID on the nodeJS server?

Edit: Is this also possible using socket-io with node.js?

Any help would be really appreciated. Thanks.

1 Answers1

1

If you just want to check if two players are in the same LAN, looking at their remoteAddress using your code should be enough. You might want to assign unique IDs to each player, so if you have 2 players with different IDs but same IP address, it means that they are in the same LAN.

On the other hand, if you really want to obtain their local IP address for other purposes, you might want to look at this answer on how to process os.networkInterfaces()

mihai
  • 37,072
  • 9
  • 60
  • 86