Created
May 29, 2012 09:46
-
-
Save adutra/2823578 to your computer and use it in GitHub Desktop.
Idea to get localhost
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static InetAddress getLocalHost() throws UnknownHostException { | |
InetAddress ret = InetAddress.getLocalHost(); | |
if (!ret.isLoopbackAddress()) { | |
//getLocalHost() did not return the loopback address | |
ret = InetAddress.getByName("localhost"); | |
if (!ret.isLoopbackAddress()) { | |
_logger.severe("" + ret.getHostAddress() + " is not a loopback address"); | |
} | |
} | |
// _logger.log(Level.SEVERE,"LoopbackAddress: "+ret.isLoopbackAddress()); | |
// _logger.log(Level.SEVERE,"LinkLocalAddress: "+ret.isLinkLocalAddress()); | |
// _logger.log(Level.SEVERE,"AnyLocalAddress: "+ret.isAnyLocalAddress()); | |
// ret=InetAddress.getByAddress(new byte[] {(byte)192,(byte)168,(byte)192,(byte)251}); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment