Here you can find the source of isPublicIP4Address(InetAddress localAddress)
public static boolean isPublicIP4Address(InetAddress localAddress)
//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(); } }