Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  55] [ 2]  / answers: 1 / hits: 24504  / 14 Years ago, tue, november 23, 2010, 12:00:00

is it possible to get hostname in Node.js?



This is how I get client's IP:



var ip = request.header('x-forwarded-for');


So, how do I get client's hostname?



var hostname = request.header('???');


Thanks for reply!


More From » node.js

 Answers
3

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.



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.


[#94871] Saturday, November 20, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mireyag

Total Points: 73
Total Questions: 107
Total Answers: 85

Location: Ukraine
Member since Sun, Dec 13, 2020
3 Years ago
mireyag questions
Sun, Aug 15, 21, 00:00, 3 Years ago
Wed, Dec 16, 20, 00:00, 3 Years ago
Tue, Sep 1, 20, 00:00, 4 Years ago
Sun, Jul 5, 20, 00:00, 4 Years ago
;