List of utility methods to do Host Name Get
InetAddress | getHostGateway() get Host Gateway @SuppressWarnings("unused") String _gateway = null, _ip = null; if (System.getProperty("os.name").startsWith("Windows")) { return parseWindows(); try { BufferedReader reader = new BufferedReader(new FileReader("/proc/net/route")); String line; ... |
String | getHostInformation() Return a string identifiying this host/user/JVM. String hostname = "unknown"; final InetAddress host; try { host = InetAddress.getLocalHost(); hostname = host.getHostName(); hostname = hostname.replaceAll("\\..*", ""); } catch (Exception ignore) { final String userName = System.getProperty("user.name"); return userName + "@" + hostname + " " + (getPid() != -1 ? "(" + getPid() + ")" : ""); |
String | getHostMac(String host) get Host Mac try { NetworkInterface network = NetworkInterface.getByInetAddress(InetAddress.getByName(host)); byte[] mac = network.getHardwareAddress(); StringBuilder sb = new StringBuilder(); for (int i = 0, ci = mac.length; i < ci; i++) { sb.append(String.format("%02X%s", mac[i], (i < ci - 1) ? "-" : "")); return sb.toString(); ... |
String | getHostName() get Host Name String hostName = null; try { InetAddress a = InetAddress.getLocalHost(); hostName = a.getHostName(); } catch (UnknownHostException e) { if (hostName == null) { boolean bFindIP = false; ... |
String | getHostname() Return this machine's hostname, or "unknown" if unable to retrieve the name. try { java.net.InetAddress addr = java.net.InetAddress.getLocalHost(); return addr.getHostName(); } catch (java.net.UnknownHostException ex) { return "unknown"; |
String | getHostName() get Host Name try { InetAddress.getLocalHost().getHostName(); return "0.0.0.0"; } catch (UnknownHostException e) { e.printStackTrace(); return "127.0.0.1"; |
String | getHostName() Gets the host name. try { final java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost(); return localMachine.getHostName(); } catch (final UnknownHostException e) { return "localhost"; |
String | getHostname() Returns the hostname if (null == _hostname) { try { _hostname = InetAddress.getLocalHost().getHostName(); } catch (Exception e) { _hostname = "UNKNOWN"; return _hostname; ... |
String | getHostName() Returns a hostname from the current host TODO: Platform dependent return System.getenv().containsKey("HOSTNAME") ? Iterables.getFirst(DOT_SPLITTER.split(System.getenv("HOSTNAME")), getInetHost()) : getInetHost(); |
String | getHostName() get Host Name InetAddress addr; try { addr = InetAddress.getLocalHost(); } catch (UnknownHostException e) { return "localhost"; return addr.getHostName(); |