Java InetAddress Check isPublicIP4Address(InetAddress localAddress)

Here you can find the source of isPublicIP4Address(InetAddress localAddress)

Description

is Public IP Address

License

Open Source License

Declaration

public static boolean isPublicIP4Address(InetAddress localAddress) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    final private static Pattern NON_PUBLIC_IP = Pattern
            .compile("^(127|192\\.168|169\\.254|2(2[4-9]|3[0-9])|172\\.(1[6-9]|2[0-9]|3[01])|255\\.255\\.255\\.255)");

    public static boolean isPublicIP4Address(InetAddress localAddress) {
        Matcher matcher = NON_PUBLIC_IP.matcher(localAddress
                .getHostAddress());//from   w ww  . j ava2  s .com
        return !matcher.find();
    }
}

Related

  1. isPrivateIP(InetAddress ip)
  2. isPrivateNetworkAddress(final InetAddress inetAddress)
  3. isPrivateSubnet(InetAddress address)
  4. isPublic(InetAddress inetAddress)
  5. isPublicIp(InetAddress addr)
  6. isPubliclyRoutable(final InetAddress addrIP)
  7. isReachable(final InetAddress inetAddress, final int timeout)
  8. isReachable(InetAddress address, int port)
  9. isReachable(NetworkInterface iface, InetAddress address, int timeout)