List of utility methods to do Host Name Get
String | getHostname() get Hostname String retHost = "UNKNOWN_HOST"; try { String host = InetAddress.getLocalHost().getCanonicalHostName(); if (host != null) { int idx = host.indexOf("."); if (idx > -1) { retHost = host.substring(0, idx); try { ... |
String | getHostName(Proxy proxy) get Host Name InetSocketAddress address = (InetSocketAddress) proxy.address();
return address.getHostName();
|
String | getHostName(String destination) get Host Name return new URL(destination).getHost(); |
String | getHostName(String host) get Host Name return InetAddress.getByName(host).getCanonicalHostName();
|
String | getHostname(String targetEndpoint) get Hostname try { URI uri = new URI(targetEndpoint); return uri.getHost(); } catch (Exception e) { return "localhost"; |
String | getHostNameByInet() Uses InetAddress.getLocalHost().getCanonicalHostName() to get the host name.
try { String inetHost = InetAddress.getLocalHost().getCanonicalHostName(); if (inetHost == null || inetHost.trim().isEmpty() || "localhost".equalsIgnoreCase(inetHost.trim())) return null; return inetHost.trim(); } catch (Exception x) { return null; |
String | getHostNameByNic() Iterates through the found NICs, extracting the host name if the NIC is not the loopback interface. try { for (Enumeration<NetworkInterface> nicEnum = NetworkInterface.getNetworkInterfaces(); nicEnum .hasMoreElements();) { NetworkInterface nic = nicEnum.nextElement(); if (nic != null && nic.isUp() && !nic.isLoopback()) { for (Enumeration<InetAddress> nicAddr = nic.getInetAddresses(); nicAddr.hasMoreElements();) { InetAddress addr = nicAddr.nextElement(); String chost = addr.getCanonicalHostName(); ... |
String | getHtmlSource(final String host) get Html Source final StringBuilder sb = new StringBuilder(); InputStream is; try { final URL url = new URL(host); is = url.openStream(); final BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; while ((line = br.readLine()) != null) { ... |
String | getInetHost() get Inet Host try { return Iterables.getFirst(DOT_SPLITTER.split(InetAddress.getLocalHost().getHostName()), "UNKNOWN_HOST"); } catch (Exception e) { return "UNKNOWN_HOST"; |
String | getLedgerAllocatorPoolName(int serverRegionId, int shardId, boolean useHostname) Retrieve the ledger allocator pool name. if (useHostname) { return String.format("allocator_%04d_%s", serverRegionId, InetAddress.getLocalHost().getHostAddress()); } else { return String.format("allocator_%04d_%010d", serverRegionId, shardId); |