Java Utililty Methods InetAddress Check

List of utility methods to do InetAddress Check

Description

The list of methods to do InetAddress Check are organized into topic(s).

Method

booleanisPrivate(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;
booleanisPrivate(InetAddress adr)
is Private
return !(isPublic(adr) || isLoopback(adr) || isTenDot(adr));
booleanisPrivateIp(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();
booleanisPrivateIp(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;
booleanisPrivateIP(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;
booleanisPrivateNetworkAddress(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.");
booleanisPrivateSubnet(InetAddress address)
Check if this is a private address, not exposed on the public Internet.
return address.isSiteLocalAddress() || address.isLoopbackAddress() || address.isLinkLocalAddress();
booleanisPublic(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.")) { 
...
booleanisPublicIp(InetAddress addr)
See if given address is public or not
return !(isPrivateIp(addr) || isLoopbackIp(addr));
booleanisPublicIP4Address(InetAddress localAddress)
is Public IP Address
Matcher matcher = NON_PUBLIC_IP.matcher(localAddress.getHostAddress());
return !matcher.find();