List of utility methods to do InetAddress Check
boolean | isThisMyIpAddress(InetAddress addr) is This My Ip Address if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) return true; try { return NetworkInterface.getByInetAddress(addr) != null; } catch (SocketException e) { return false; |
boolean | isUDPPortFree(int port, InetAddress addr) is UDP Port Free DatagramSocket ds = null; try { ds = new DatagramSocket(port, addr); return true; } catch (IOException io) { } finally { if (ds != null) { ds.close(); ... |
boolean | isUnicastAddress(@CheckForNull InetAddress address) Determines whether the given address is a "useful" unicast address. return (address != null) && !address.isAnyLocalAddress() && !address.isLoopbackAddress()
&& !address.isMulticastAddress();
|
boolean | isValidAddress(InetAddress address, int timeoutMs) Tests if the address is externally resolvable. return !address.isAnyLocalAddress() && !address.isLinkLocalAddress() && !address.isLoopbackAddress() && address.isReachable(timeoutMs) && (address instanceof Inet4Address); |
boolean | isValidAddress(InetAddress i, boolean includeLocalAddressesInNoderefs) is Valid Address if (i.isAnyLocalAddress()) { return false; } else if (i.isLinkLocalAddress() || i.isLoopbackAddress() || i.isSiteLocalAddress()) { if (includeLocalAddressesInNoderefs) { return true; } else return false; } else if (i.isMulticastAddress()) { ... |
boolean | isValidAddress(InetAddress i, boolean includeLocalAddressesInNoderefs) is Valid Address if (i.isAnyLocalAddress()) { return false; } else if (i.isLinkLocalAddress() || i.isLoopbackAddress() || isSiteLocalAddress(i)) { if (includeLocalAddressesInNoderefs) { return true; } else return false; } else if (i.isMulticastAddress()) { ... |
boolean | isValidCiscoWildcard(InetAddress wildcard) Determines if a specified address is a valid Cisco Wildcard (cisco's representation of a netmask) byte[] segments = wildcard.getAddress(); for (int i = 0; i < segments.length; i++) { assert (((byte) ~(byte) ~segments[i]) == segments[i]); segments[i] = (byte) ~segments[i]; return isValidNetmask(segments); |
boolean | isValidInetAddress(String address) is Valid Inet Address try { InetAddress.getByName(address); return true; } catch (UnknownHostException e) { return false; |
void | isValidInetAddress(String ip) is Valid Inet Address if (ip != null && !ip.isEmpty()) { if (!ip.contains(":")) { String[] segments = ip.split("\\."); if (segments.length != 4) { throw new IllegalArgumentException("IP does not appear valid:" + ip); try { InetAddress.getByName(ip); ... |
void | isValidInetAddress(String IP) Verify if IP string is an IPv4 address. if (IP == null || IP.isEmpty()) { throw new IllegalArgumentException("IP is missing or empty"); if (IP.contains(":")) { } else { String[] segments = IP.split("\\."); if (segments.length != 4) { throw new IllegalArgumentException("IP does not appear valid:" + IP); ... |