List of utility methods to do Host Name Get
String | getFile(String host, String savePath) Get a file from a host uri, and save it into the save path InputStream input = null; FileOutputStream writeFile = null; String path = new String(); try { URL url = new URL(host); URLConnection connection = url.openConnection(); int fileLength = connection.getContentLength(); if (fileLength == -1) { ... |
String | getFullHostname() get Full Hostname String hostname = "unknown"; try { final InetAddress host = InetAddress.getLocalHost(); hostname = host.getHostName(); } catch (Exception ignore) { return hostname; |
String | getFullyQualifiedDomainName(String unqualifiedHostname) Converts a hostname into a canonical hostname. if (unqualifiedHostname == null) { throw new IllegalStateException("Hostname cannot be null."); } else if (unqualifiedHostname.length() == 0) { throw new IllegalStateException("Hostname cannot be zero length."); try { return InetAddress.getByName(unqualifiedHostname).getCanonicalHostName().toLowerCase(); } catch (UnknownHostException e) { ... |
String | getFullyQualifiedHostName() get Fully Qualified Host Name String localhost = null; try { localhost = InetAddress.getLocalHost().getCanonicalHostName().toLowerCase(); } catch (UnknownHostException e) { e.printStackTrace(); localhost = "Unknown Host"; return localhost; ... |
String | getHost() Gets the hostname of the machine running the code, foregoing the need for exception handling in-line when this information is needed. String host = "unknown"; try { host = InetAddress.getLocalHost().getHostName(); } catch (final UnknownHostException ex) { ex.printStackTrace(); return host; |
String | getHost() get Host try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface current = interfaces.nextElement(); if (!current.isUp() || current.isLoopback() || current.isVirtual()) continue; if (current.getName().contains("lxc")) continue; ... |
String | getHost(String host) Returns the host address, if the supplied host is localhost, else returns it, unchanged. if (host.equals("localhost")) { try { host = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException ignore) { return host; |
String | getHost(String link) get Host URL url; String host = ""; try { url = new URL(link); host = url.getHost(); } catch (MalformedURLException e) { return host; ... |
String | getHost(String s) get Host if (s == null) { return null; try { InetAddress address = InetAddress.getByName(s); return address.getHostName(); } catch (UnknownHostException ex) { System.out.println("Could not find server hostname " + s); ... |
String | getHostCore(final String quadGraph) This method should be used over others because it -safely- and accurately trims the host name by 1. final String[] graphurisplit = quadGraph.split("\\."); StringBuilder host = new StringBuilder(); try { Integer.valueOf(graphurisplit[graphurisplit.length - 1]); host.append(quadGraph); } catch (NumberFormatException e) { for (int i = Math.min(1, Math.max(graphurisplit.length - 2, 0)); i < graphurisplit.length; i++) { host.append(graphurisplit[i] + "."); ... |