I am trying to filter out private network IPfrom URLs.
Previously I had this code
if(!sCurrentLine.startsWith("192.168") && !sCurrentLine.startsWith("172.") && !sCurrentLine.startsWith("10.")&& !sCurrentLine.startsWith("127.0.0"))
Data Example
10.1.1.83/nagiosxi/
10.1.1.83/nagiosxi//rr.php?uid=18-c96b5fb53f9
127.0.0.1/tkb/internet/
172.18.20.200/cgi-bin/topstats.pl?submit_type=topstats&time=00:2
Here is my new code
Pattern privateIp=Pattern.compile("(^127\\.0\\.0\\.1)|(^10\\.)|(^172\\.1[6-9]\\.)|(^172\\.2[0-9]\\.)|(^172\\.3[0-1]\\.)|(^192\\.168\\.)");
while((sCurrentLine=br.readLine())!=null)
{
Matcher pnm=privateIp.matcher(sCurrentLine);
if(!pnm.matches())
{
System.out.println("not match");
}
}
I am thinking of using Pattern Match. However, Pattern.compile
doesn't take this regular expression.
Or is there any function that can handle private network IP.
Any thought on that?