How to get client machine name in nodejs web application?

In this article, we are going to learn How to get client machine name or host name, ip address of the client system or any system in nodejs.

Use of DNs Reverse LookUp

You can use NodeJs DNS reverse Lookup. check here if you want to read more about it.

require('dns').reverse(req.connection.remoteAddress, function(err, domains) { console.log(domains);});

How to get ip Address of the client system ?

const ip = (req.headers["X-Forwarded-For"] || req.headers["x-forwarded-for"] || '').split(',')[0] 
|| req.connection.remoteAddress;

console.log("ip address is:- " + ip);

How to get Host name of the client system.

if you are trying to get the host name of the client system or any system, you can do as follow.

const os = require('os');const hostname = os.hostname(); console.log("Hostname is: " + hostname);