List of utility methods to do InetAddress Create
String | getHostAddress(InetAddress anAddress) Normalized version of java.net.InetAddress#getHostAddress() that handles IPv6 addresss formatting using the style of IETF RFC 2732 and also handles removal of IPv6 scoping identifiers. String hostAddress; if (anAddress instanceof Inet6Address) { hostAddress = anAddress.getHostAddress(); int percentAt = hostAddress.indexOf('%'); if (-1 == percentAt) { hostAddress = "[" + hostAddress + "]"; } else { hostAddress = "[" + hostAddress.substring(0, percentAt) + "]"; ... |
String | getHostAddress(InetAddress host) get Host Address String hostAddr = host.getHostAddress(); if (host instanceof Inet6Address) { if (hostAddr.lastIndexOf('%') >= 0) { hostAddr = hostAddr.substring(0, hostAddr.lastIndexOf('%')); return hostAddr; |
String | getHostName(InetAddress address) This method tries to determine the hostname of the given InetAddress without triggering a reverse DNS lookup. String result; String hostAddress = address.getHostAddress(); String inetAddr = address.toString(); int index1 = inetAddr.lastIndexOf('/'); int index2 = inetAddr.indexOf(hostAddress); if (index2 == index1 + 1) { if (index1 == 0) { result = hostAddress; ... |
String | getHostName(InetAddress ia) get Host Name return ia.getHostName();
|
String | getHostNameReliably(final String requestingHost, final InetAddress site, final URL requestingUrl) get Host Name Reliably String host = requestingHost; if (host == null) { if (site != null) { host = site.getHostName(); } else if (requestingUrl != null) { host = requestingUrl.getHost(); host = host == null ? "" : host; return host; |
String | getHostNameWithoutDomain(final InetAddress addr) get Host Name Without Domain final String hostName = addr.getHostName(); final int pos = hostName.indexOf('.'); if (pos == -1) { return hostName; } else { return hostName.substring(0, pos); |
InetAddress | getInetAddress() get Inet Address try { return InetAddress.getLocalHost(); } catch (UnknownHostException e) { hostName = "unknown host!"; return null; |
String | getInetAddress() get Inet Address try { InetAddress inet = InetAddress.getLocalHost(); return inet.getHostAddress(); } catch (UnknownHostException e) { e.printStackTrace(); return ""; |
InetAddress | getInetAddress() get Inet Address InetAddress currentAddress = null; try { InetAddress addrs[] = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName()); for (InetAddress addr : addrs) { if (!addr.isLoopbackAddress() && addr.isSiteLocalAddress()) { currentAddress = addr; break; if (currentAddress == null || currentAddress.getHostAddress() == null || currentAddress.getHostAddress().length() == 0) { try { Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface iface : Collections.list(ifaces)) { Enumeration<InetAddress> raddrs = iface.getInetAddresses(); for (InetAddress raddr : Collections.list(raddrs)) { if (!raddr.isLoopbackAddress() && raddr.isSiteLocalAddress()) { currentAddress = raddr; break; } catch (SocketException e) { e.printStackTrace(); } catch (UnknownHostException e) { if (currentAddress != null && currentAddress.getHostAddress() != null && currentAddress.getHostAddress().length() > 0) { return currentAddress; return null; |
InetAddress | getInetAddress() Return the local host address InetAddress address = null; try { address = getFirstNonLoopbackAddress(false, false); } catch (SocketException e) { e.printStackTrace(); if (address == null) { address = InetAddress.getLocalHost(); ... |