blob: b8e713e88046b6f33cc9235e4749f949ff88e223 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package com.btr.proxy.selector.whitelist;
import java.util.regex.Pattern;
/*****************************************************************************
* Checks if the given string is a IP4 range subnet definition
* of the format 192.168.0/24
* Based on a contribution by Jan Engler
* @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
****************************************************************************/
public class IPv4WithSubnetChecker {
private static Pattern IP_SUB_PATTERN = Pattern.compile(
"^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])/(\\d|([12]\\d|3[0-2]))$");
/*************************************************************************
* Tests if a given string is of in the correct format for an IP4 subnet mask.
* @param possibleIPAddress to test for valid format.
* @return true if valid else false.
************************************************************************/
public static boolean isValid(String possibleIPAddress) {
return IP_SUB_PATTERN.matcher(possibleIPAddress).matches();
}
}
|