在Node.js中获取客户端主机名 [英] Getting client hostname in Node.js
问题描述
是否可以在Node.js中获取主机名?
is it possible to get hostname in Node.js?
这就是我获取客户端IP的方式:
var ip = request.header('x-forwarded-for');
那么,我如何获得客户的主机名?
var hostname = request.header('???');
感谢您的回复!
推荐答案
我认为你能做到的唯一方法就是这样:
I think the only way you can do it is like this:
<form method="post" action="/gethostname">
<label for="hostname">What is your hostname?</label>
<input type="text" name="hostname" id="hostname">
</form>
但我建议你真的不需要它,它不像你可以做任何有用的事情信息。如果你只是想要一个字符串来识别用户的机器,那么你可以做些什么。
But I would suggest you don't really need it, it's not like you can do anything useful with the information. If you just want a string to identify with the user's machine then you can make something up.
如果你真正关注的是FQDN那么我会建议它仍然是对你没那么有用,但为此你需要反向DNS查找。如果您使用VPS或类似设备,您可以配置您的盒子为您执行此操作,但请注意,它可能需要几秒钟,因此在响应中执行此操作并不是一个好主意。另请注意,在大多数情况下,您不会获得用户机器的FQDN,而是路由器的FQDN。
If what you're really after is the FQDN then I would suggest it's still not really that useful to you, but for that you need Reverse DNS lookup. If you're on a VPS or similar you can probably configure your box to do this for you, but note that it'll likely take a few seconds so it's not a good idea to do it as part of a response. Also note, you'll not be getting the user's machine's FQDN in most cases but that of their router.
这篇关于在Node.js中获取客户端主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!