List of utility methods to do Local Host Get
List | getLocalHosts() Get host IP address List<String> list = new ArrayList<>(); try { Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); while (nets.hasMoreElements()) { NetworkInterface ni = (NetworkInterface) nets.nextElement(); Enumeration<InetAddress> itor = ni.getInetAddresses(); while (itor.hasMoreElements()) { InetAddress inetAddress = itor.nextElement(); ... |
boolean | isLocalHost(String address) Indica si la direccion IP/host que se pasa como parametro pertenece a la maquina local o no if ((address == null) || (address.equals(""))) { return false; try { InetAddress ia = InetAddress.getByName(address); if (ia.isLoopbackAddress()) { return true; NetworkInterface ni = NetworkInterface.getByInetAddress(ia); return ni != null; } catch (SocketException se) { return false; } catch (UnknownHostException uhe) { return false; |
boolean | isLocalHost(String h1) is Local Host boolean ret = false; try { InetAddress a1 = InetAddress.getByName(h1); if (a1 != null) ret = InetAddress.getLocalHost().getHostAddress().equals(a1.getHostAddress()); } catch (UnknownHostException e) { return ret; ... |
boolean | isLocalhost(String host) is Localhost InetAddress address; try { address = InetAddress.getByName(host); } catch (UnknownHostException e) { return false; if (address.isAnyLocalAddress() || address.isLoopbackAddress()) return true; ... |
boolean | isLocalhost(String hostname) Check if a hostname is the local host. assert null != hostname : "hostname to check cannot be null!"; boolean isLocalhost = false; try { InetAddress remoteHost = InetAddress.getByName(hostname); InetAddress localHost = InetAddress.getLocalHost(); InetAddress loopback = InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }); if (remoteHost.equals(localHost) || remoteHost.equals(loopback)) { isLocalhost = true; ... |
boolean | isLocalhost(String someHost) is Localhost if (null == someHost) { return false; try { InetAddress localHostAddr = InetAddress.getLocalHost(); InetAddress someAddr = InetAddress.getByName(someHost); return localHostAddr.equals(someAddr); } catch (UnknownHostException uhe) { ... |
boolean | isLocalHostNameInList(String[] hostList) is Local Host Name In List String localHostName = getLocalHostName(); if (localHostName == null) { return false; for (String host : hostList) { if (host.equalsIgnoreCase(localHostName)) { return true; return false; |