Java InetAddress Check isPrivateSubnet(InetAddress address)

Here you can find the source of isPrivateSubnet(InetAddress address)

Description

Check if this is a private address, not exposed on the public Internet.

License

Apache License

Return

true if the address is private

Declaration

public static boolean isPrivateSubnet(InetAddress address) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.InetAddress;

public class Main {
    /**//from ww w. j av a2s . c o m
     * Check if this is a private address, not exposed on the public Internet.
     *
     * For IPV4 addresses this is an RFC1918 subnet address ({code 10.0.0.0/8},
     * {@code 172.16.0.0/12} and {@code 192.168.0.0/16}), a link-local address
     * ({@code 169.254.0.0/16}) or a loopback address ({@code 127.0.0.1/0}).
     * <p>
     * For IPV6 addresses this is the RFC3514 link local block ({@code fe80::/10})
     * and site local block ({@code feco::/10}) or the loopback block
     * ({@code ::1/128}).
     *
     * @return true if the address is private
     */
    public static boolean isPrivateSubnet(InetAddress address) {
        return address.isSiteLocalAddress() || address.isLoopbackAddress() || address.isLinkLocalAddress();
    }
}

Related

  1. isPrivate(InetAddress adr)
  2. isPrivateIp(final InetAddress address)
  3. isPrivateIp(InetAddress addr)
  4. isPrivateIP(InetAddress ip)
  5. isPrivateNetworkAddress(final InetAddress inetAddress)
  6. isPublic(InetAddress inetAddress)
  7. isPublicIp(InetAddress addr)
  8. isPublicIP4Address(InetAddress localAddress)
  9. isPubliclyRoutable(final InetAddress addrIP)