diff options
Diffstat (limited to 'src/main/java/com/btr/proxy/selector/whitelist/IPv4WithSubnetChecker.java')
-rw-r--r-- | src/main/java/com/btr/proxy/selector/whitelist/IPv4WithSubnetChecker.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main/java/com/btr/proxy/selector/whitelist/IPv4WithSubnetChecker.java b/src/main/java/com/btr/proxy/selector/whitelist/IPv4WithSubnetChecker.java new file mode 100644 index 0000000..b8e713e --- /dev/null +++ b/src/main/java/com/btr/proxy/selector/whitelist/IPv4WithSubnetChecker.java @@ -0,0 +1,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(); + } +} |