Can any one help me in getting clients machine-name/host-name for my website authentication.which is running internally in my pany domain. I tried the below code but got server host-name instead of client.
var os = require("os");
var hostaddress = os.hostname();
I know a way to get ip address of client using below code
req.connection.remoteAddress
Since ip address will change in change of internet connection.I want to autenticate with puter name.Please help me in getting puter name of client login to my site.
Can any one help me in getting clients machine-name/host-name for my website authentication.which is running internally in my pany domain. I tried the below code but got server host-name instead of client.
var os = require("os");
var hostaddress = os.hostname();
I know a way to get ip address of client using below code
req.connection.remoteAddress
Since ip address will change in change of internet connection.I want to autenticate with puter name.Please help me in getting puter name of client login to my site.
Share Improve this question asked Feb 10, 2017 at 4:23 HarryHarry 3733 gold badges6 silver badges13 bronze badges 1- did you get the client puter name ? – Anil Talla Commented Jul 24, 2019 at 14:00
4 Answers
Reset to default 2NodeJS DNS Reverse Lookup will do the trick. It is the only way. Check this link for more information :)
https://nodejs/api/dns.html#dns_dns_reverse_ip_callback
Try this below code
require('dns').reverse(req.connection.remoteAddress, function(err, domains) {
console.log(domains);
});
To get ip Address of the client system or of any system you can do this.
Change req to whatever nomenclatural you are using
var ip = (req.headers["X-Forwarded-For"] || req.headers["x-forwarded-for"] || '').split(',')[0] || req.connection.remoteAddress;
console.log("ip address is:- " + ip);
To get the host name of the client system or of any system you can do this
const os = require('os');
var hostname = os.hostname();
console.log("Hostname is:- " + hostname);
This will work on both js and nodejs
function getClientAddress(req) {
return req.headers['x-forwarded-for'] || req.connection.remoteAddress;
}
This will work !!
So, how do I get client's hostname?
request.headers.host
hope this also works for you.