KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
This sounds like something that should have been asked before, and it has sort of, but I'm looking to get the local hostname and IP addresses of a machine even when it is not resolvable through DNS (in Java). I can get the local IP addresses without resolution by iterating through NetworkInterfaces.getNetworkInterfaces() . Any answers to this question I've found indicate to use getLocalHost() InetAddress localhost = java.net.InetAddress.getLocalHost(); hostName = localhost.getHostName(); but this throws an UnknownHostException if the hostname isn't resolvable through DNS. Is there no way to get the local hostname without a DNS lookup happening behind the scenes? edit: the IP address retrieved is 10.4.168.23 The exception is java.net.UnknownHostException: cms1.companyname.com: cms1.companyname.com (hostname changed for pseudo-anonymity), and the hosts file does not contain the hostname. But it does know its hostname, so I'm not sure why I can't get it without an exception being thrown.
Tags (comma-separated)
Save Edits
Cancel