List of utility methods to do InetAddress Check
boolean | isPrivate(InetAddress addr) is Private byte[] addrb = addr.getAddress(); for (int i = PRIVATE_ADDRS.length; --i >= 0;) { boolean valid = true; for (int j = 0; j < PRIVATE_ADDRS[i].length; j++) if (PRIVATE_ADDRS[i][j] != (addrb[j] & 0xFF)) { valid = false; break; if (valid) return true; return false; |
boolean | isPrivate(InetAddress adr) is Private return !(isPublic(adr) || isLoopback(adr) || isTenDot(adr));
|
boolean | isPrivateIp(final InetAddress address) Determines if a given IP address is private. Objects.requireNonNull("IP address must be present"); return address.isAnyLocalAddress() || address.isLoopbackAddress() || address.isLinkLocalAddress() || address.isSiteLocalAddress(); |
boolean | isPrivateIp(InetAddress addr) See if given address is private or not boolean result = false; if (addr instanceof Inet4Address) { result = isPrivateIp((Inet4Address) addr); } else if (addr instanceof Inet6Address) { result = isPrivateIp((Inet6Address) addr); return result; |
boolean | isPrivateIP(InetAddress ip) Determines if the supplied IP Address is a private non-routed IP Address. if (ip.isSiteLocalAddress()) return true; else if (ip instanceof Inet6Address) return ip.getAddress()[0] == IP6_PRIVATE_PREFIX; return false; |
boolean | isPrivateNetworkAddress(final InetAddress inetAddress) Returns whether the given internet address is reserved for private networks, such as those behind a NAT router. assert inetAddress != null : "inetAddress must not be null"; final String inetAddressString = inetAddress.getHostAddress(); return inetAddressString.startsWith("192.168.") || inetAddressString.startsWith("10.") || inetAddressString.startsWith("172."); |
boolean | isPrivateSubnet(InetAddress address) Check if this is a private address, not exposed on the public Internet. return address.isSiteLocalAddress() || address.isLoopbackAddress() || address.isLinkLocalAddress();
|
boolean | isPublic(InetAddress inetAddress) is Public String hostAddress = inetAddress.getHostAddress(); if (hostAddress.startsWith("10.") || hostAddress.startsWith("192.168.") || hostAddress.startsWith("169.254.") || hostAddress.startsWith("127.")) { return false; if (hostAddress.startsWith("172.")) { ... |
boolean | isPublicIp(InetAddress addr) See if given address is public or not return !(isPrivateIp(addr) || isLoopbackIp(addr));
|
boolean | isPublicIP4Address(InetAddress localAddress) is Public IP Address Matcher matcher = NON_PUBLIC_IP.matcher(localAddress.getHostAddress());
return !matcher.find();
|