Package com.axelor.common.net
Class IpAddressMatcher
java.lang.Object
com.axelor.common.net.IpAddressMatcher
Matches IP addresses against an IP address or a CIDR range.
Both IPv4 and IPv6 are supported. IPv4-mapped IPv6 addresses (e.g. ::ffff:192.0.2.1)
are handled as their IPv4 equivalent.
Only literal IP addresses are accepted: host names are rejected and no DNS lookup is ever performed.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether the address matches this IP address or CIDR range.booleanmatches(InetAddress address) Checks whether the address matches this IP address or CIDR range.static booleanmatchesAny(Collection<IpAddressMatcher> matchers, String address) Checks whether an address matches any of the given matchers.static IpAddressMatcherCreates a matcher from an IP address (e.g.static InetAddressparseAddress(String value) Parses a literal IP address, without any DNS lookup.static List<IpAddressMatcher> Parses a comma-separated list of IP addresses or CIDR ranges.Splits a comma-separated list of IP addresses or CIDR ranges.toString()Returns the normalized IP address or CIDR range.
-
Method Details
-
of
Creates a matcher from an IP address (e.g.192.0.2.1) or a CIDR range (e.g.192.0.2.0/24,2001:db8::/32).Host bits of a CIDR range are cleared, so
192.0.2.1/24is the same as192.0.2.0/24.- Parameters:
value- the IP address or CIDR range- Returns:
- the matcher
- Throws:
IllegalArgumentException- if the value is not a valid IP address or CIDR range
-
splitList
Splits a comma-separated list of IP addresses or CIDR ranges.Entries are trimmed and empty entries are ignored.
- Parameters:
value- the list- Returns:
- the entries, empty if the value is blank
-
parseList
Parses a comma-separated list of IP addresses or CIDR ranges.- Parameters:
value- the list- Returns:
- the matchers, empty if the value is blank
- Throws:
IllegalArgumentException- if any entry is not a valid IP address or CIDR range
-
matchesAny
Checks whether an address matches any of the given matchers.- Parameters:
matchers- the matchersaddress- the IP address- Returns:
trueif the address is a valid IP address matched by any matcher
-
parseAddress
Parses a literal IP address, without any DNS lookup.IPv6 addresses may be enclosed in brackets and may have a zone index (
%eth0), which is ignored. IPv4-mapped IPv6 addresses are converted to IPv4 addresses.- Parameters:
value- the IP address- Returns:
- the address, or
nullif the value is not a literal IP address
-
matches
Checks whether the address matches this IP address or CIDR range.- Parameters:
address- the IP address- Returns:
trueif matching,falseotherwise or if the address is invalid
-
matches
Checks whether the address matches this IP address or CIDR range.- Parameters:
address- the IP address- Returns:
trueif matching,falseotherwise
-
toString
Returns the normalized IP address or CIDR range.
-