List of utility methods to do Local Host Get
String | getLocalHost() Returns the non-localhost IP address of the current machine. String address = null; try { address = InetAddress.getLocalHost().getHostAddress(); if (address.equals(LOCAL_HOST)) { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); boolean found = false; while (interfaces.hasMoreElements() && !found) { NetworkInterface e = interfaces.nextElement(); ... |
InetAddress | getLocalHost() get Local Host try { return (InetAddress.getLocalHost()); } catch (Throwable e) { try { Enumeration nis = NetworkInterface.getNetworkInterfaces(); while (nis.hasMoreElements()) { NetworkInterface ni = (NetworkInterface) nis.nextElement(); Enumeration addresses = ni.getInetAddresses(); ... |
InetAddress | getLocalHost() get Local Host try { return InetAddress.getLocalHost(); } catch (UnknownHostException e) { throw new AssertionError(e); |
String | getLocalHost() get Local Host try { return InetAddress.getLocalHost().getCanonicalHostName(); } catch (final UnknownHostException uhe) { final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { final NetworkInterface networkInterface = interfaces.nextElement(); if (null != networkInterface) { final Enumeration<InetAddress> addresses = networkInterface.getInetAddresses(); ... |
InetAddress | getLocalHost() Use this instead of InetAddress#getLocalHost() to prevent multiple lookups. if (localhost == null) { try { localhost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { throw new RuntimeException(e); return localhost; ... |
InetAddress | getLocalHost() Methods returns InetAddress for localhost InetAddress addr; try { addr = InetAddress.getLocalHost(); } catch (ArrayIndexOutOfBoundsException e) { addr = InetAddress.getByName(null); return addr; |
InetAddress | getLocalHost() get Local Host try { return InetAddress.getLocalHost(); } catch (UnknownHostException e) { return getLocalHostByName(); |
InetAddress | getLocalHost() Smarter way to get localhost than InetAddress.getLocalHost. String osName = System.getProperty("os.name"); if (osName != null && osName.toLowerCase().contains("windows")) { return InetAddress.getLocalHost(); InetAddress loopback = null; Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); while (e.hasMoreElements()) { NetworkInterface i = e.nextElement(); ... |
InetAddress | getLocalHost() Returns an InetAddress representing the address of the localhost. InetAddress localHost = InetAddress.getLocalHost(); if (!localHost.isLoopbackAddress()) { return localHost; InetAddress[] addrs = getAllLocalUsingNetworkInterface(); for (InetAddress addr : addrs) { if (!addr.isLoopbackAddress() && !addr.getHostAddress().contains(":")) { return addr; ... |
InetSocketAddress | getLocalHost() get Local Host try { return new InetSocketAddress(InetAddress.getByName("192.168.0.10"), 0); } catch (final UnknownHostException e) { return null; |