最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get client computer name in node js - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

4 Answers 4

Reset to default 2

NodeJS 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.

发布评论

评论列表(0)

  1. 暂无评论