3

Can any one help me in getting clients machine-name/host-name for my website authentication.which is running internally in my company 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 computer name.Please help me in getting computer name of client login to my site.

1
  • did you get the client computer name ? Commented Jul 24, 2019 at 14:00

4 Answers 4

2

NodeJS DNS Reverse Lookup will do the trick. It is the only way. Check this link for more information :)

https://nodejs.org/api/dns.html#dns_dns_reverse_ip_callback

Try this below code

require('dns').reverse(req.connection.remoteAddress, function(err, domains) {
    console.log(domains);
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much.This is helpful.Thank you again.
@Yalamanchili why did you reject my edit on your answer ? Did you at least test your code, it's not working because of the ' after remoteAddress or am I wrong ?
1

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

1 Comment

os.hostname you will not be getting the hostname of the client, but the server hostname.
0
function getClientAddress(req) {
  return req.headers['x-forwarded-for'] || req.connection.remoteAddress;
}

This will work !!

3 Comments

Hi,I need to get client hostname.not ipaddress :(
if you are using express, then you can do as follows, var express = require("express"); var app = express.createServer(); app.listen(8080); app.get("/", function (req, res){ console.log("REQ:: "+req.headers.host); res.end(req.headers.host); });
@harikrishna got your answer ?
0

So, how do I get client's hostname?

  request.headers.host

hope this also works for you.

3 Comments

No..getting "Undefined" as output
can you visit this page stackoverflow.com/questions/4255264/… , hope this solve your issue
fyi: this is a user reported value, letting the server know, where to route the request. It is not related to the client and little to the server hostname.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.