In order to distinguish internal and external users, I'm using java regular expressions within scriplet tags and the code is below:
String ipAddress = request.getHeader("iv-remote-address");
String internalIPs =
"166.41.8.X" + "|" +"12.16.X.X" + "|" +"12.22.X.X" + "|" +"132.23.X.X" + "|";
Pattern p = Pattern.compile("^(?:"+internalIPs.replaceAll("X", "(?:\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])")+")$");
Matcher m = p.matcher(ipAddress);
if (m.matches())
{
//print internal IP
} else{
//print external IP
}
If the input is 166.41.8.2, the IP address is correctly identified as internal IP if the input is 12.16.2.1 or 12.22.12.3, the IP address is not correctly identified as internal IP. I guess that has to do with matching pattern with 2 "X"s. Can anybody identify the issue with pattern matching? Or could recommend a best way of matching pattern of IP addresses?