Package org.jivesoftware.util
Class IpUtils
java.lang.Object
org.jivesoftware.util.IpUtils
Various utility methods for working with (string representations of) IP-addresses.
- Author:
- Guus der Kinderen, guus@goodbytes.nl
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Replaces a representation of an IPv4 network range that is using wildcards (eg: 192.*.*.*) with a notation that is CIDR-based (eg: 192.0.0.0/8).static boolean
isAddressInAnyOf
(byte[] address, Set<String> addressesAndRanges) Checks if the provided address is matched by any of the addresses or address ranges.static boolean
isAddressInAnyOf
(com.github.jgonian.ipmath.Ipv4 address, Set<com.github.jgonian.ipmath.Ipv4> addresses, Set<com.github.jgonian.ipmath.Ipv4Range> ranges) Checks if the provided address is matched by any of the addresses or address ranges.static boolean
isAddressInAnyOf
(com.github.jgonian.ipmath.Ipv4 address, Set<String> addressesAndRanges) Checks if the provided address is matched by any of the addresses or address ranges.static boolean
isAddressInAnyOf
(com.github.jgonian.ipmath.Ipv6 address, Set<com.github.jgonian.ipmath.Ipv6> addresses, Set<com.github.jgonian.ipmath.Ipv6Range> ranges) Checks if the provided address is matched by any of the addresses or address ranges.static boolean
isAddressInAnyOf
(com.github.jgonian.ipmath.Ipv6 address, Set<String> addressesAndRanges) Checks if the provided address is matched by any of the addresses or address ranges.static boolean
isAddressInAnyOf
(String address, Set<String> addressesAndRanges) Checks if the provided address is matched by any of the addresses or address ranges.static boolean
isAddressInAnyOf
(InetAddress address, Set<String> addressesAndRanges) Checks if the provided address is matched by any of the addresses or address ranges.static boolean
isValidIpAddress
(String value) Checks if the provided value is a representation of an IP address.static boolean
isValidIpAddressOrRange
(String value) Checks if the provided value is a representation of an IP address or an IP address range.static boolean
isValidIpRange
(String value) Checks if the provided value is a representation of an IP address range.static boolean
isValidIpv4
(String value) Checks if the provided value is a representation of an IPv4 address.static boolean
isValidIpv4Range
(String value) Checks if the provided value is a representation of an IPv4 address range.static boolean
isValidIpv6
(String value) Checks if the provided value is a representation of an IPv6 address.static boolean
isValidIpv6Range
(String value) Checks if the provided value is a representation of an IPv6 address range.static String
removeBracketsFromIpv6Address
(String address) When the provided input is an IPv6 literal that is enclosed in brackets (the [] style as expressed in https://tools.ietf.org/html/rfc2732 and https://tools.ietf.org/html/rfc6874), this method returns the value stripped from those brackets (the IPv6 address, instead of the literal).
-
Constructor Details
-
IpUtils
public IpUtils()
-
-
Method Details
-
isAddressInAnyOf
public static boolean isAddressInAnyOf(@Nonnull byte[] address, @Nonnull Set<String> addressesAndRanges) Checks if the provided address is matched by any of the addresses or address ranges.- Parameters:
address
- The address to look up.addressesAndRanges
- the values to compare the provided address with.- Returns:
- true if the address is found in the addresses or ranges, otherwise false.
-
isAddressInAnyOf
public static boolean isAddressInAnyOf(@Nonnull String address, @Nonnull Set<String> addressesAndRanges) Checks if the provided address is matched by any of the addresses or address ranges.- Parameters:
address
- The address to look up.addressesAndRanges
- the values to compare the provided address with.- Returns:
- true if the address is found in the addresses or ranges, otherwise false.
-
isAddressInAnyOf
public static boolean isAddressInAnyOf(@Nonnull InetAddress address, @Nonnull Set<String> addressesAndRanges) Checks if the provided address is matched by any of the addresses or address ranges.- Parameters:
address
- The address to look up.addressesAndRanges
- the values to compare the provided address with.- Returns:
- true if the address is found in the addresses or ranges, otherwise false.
-
isAddressInAnyOf
public static boolean isAddressInAnyOf(@Nonnull com.github.jgonian.ipmath.Ipv4 address, @Nonnull Set<String> addressesAndRanges) Checks if the provided address is matched by any of the addresses or address ranges.- Parameters:
address
- The address to look up.addressesAndRanges
- the values to compare the provided address with.- Returns:
- true if the address is found in the addresses or ranges, otherwise false.
-
isAddressInAnyOf
public static boolean isAddressInAnyOf(@Nonnull com.github.jgonian.ipmath.Ipv6 address, @Nonnull Set<String> addressesAndRanges) Checks if the provided address is matched by any of the addresses or address ranges.- Parameters:
address
- The address to look up.addressesAndRanges
- the values to compare the provided address with.- Returns:
- true if the address is found in the addresses or ranges, otherwise false.
-
isAddressInAnyOf
public static boolean isAddressInAnyOf(@Nonnull com.github.jgonian.ipmath.Ipv4 address, @Nonnull Set<com.github.jgonian.ipmath.Ipv4> addresses, @Nonnull Set<com.github.jgonian.ipmath.Ipv4Range> ranges) Checks if the provided address is matched by any of the addresses or address ranges.- Parameters:
address
- The address to look up.addresses
- the address-values to compare the provided address with.ranges
- the range-values to compare the provided address with.- Returns:
- true if the address is found in the addresses or ranges, otherwise false.
-
isAddressInAnyOf
public static boolean isAddressInAnyOf(@Nonnull com.github.jgonian.ipmath.Ipv6 address, @Nonnull Set<com.github.jgonian.ipmath.Ipv6> addresses, @Nonnull Set<com.github.jgonian.ipmath.Ipv6Range> ranges) Checks if the provided address is matched by any of the addresses or address ranges.- Parameters:
address
- The address to look up.addresses
- the address-values to compare the provided address with.ranges
- the range-values to compare the provided address with.- Returns:
- true if the address is found in the addresses or ranges, otherwise false.
-
removeBracketsFromIpv6Address
When the provided input is an IPv6 literal that is enclosed in brackets (the [] style as expressed in https://tools.ietf.org/html/rfc2732 and https://tools.ietf.org/html/rfc6874), this method returns the value stripped from those brackets (the IPv6 address, instead of the literal). In all other cases, the input value is returned.- Parameters:
address
- The value from which to strip brackets.- Returns:
- the input value, stripped from brackets if applicable.
-
convertIpv4WildcardRangeToCidrNotation
Replaces a representation of an IPv4 network range that is using wildcards (eg: 192.*.*.*) with a notation that is CIDR-based (eg: 192.0.0.0/8). When the string cannot be transformed, the original string is returned.- Parameters:
value
- The network range to transform- Returns:
- The transformed range.
-
isValidIpv4
Checks if the provided value is a representation of an IPv4 address.- Parameters:
value
- the value to check- Returns:
- true if the provided value is an IPv4 address, otherwise false.
-
isValidIpv4Range
Checks if the provided value is a representation of an IPv4 address range.- Parameters:
value
- the value to check- Returns:
- true if the provided value is an IPv4 address range, otherwise false.
-
isValidIpv6
Checks if the provided value is a representation of an IPv6 address.- Parameters:
value
- the value to check- Returns:
- true if the provided value is an IPv6 address, otherwise false.
-
isValidIpv6Range
Checks if the provided value is a representation of an IPv6 address range.- Parameters:
value
- the value to check- Returns:
- true if the provided value is an IPv6 address range, otherwise false.
-
isValidIpAddress
Checks if the provided value is a representation of an IP address.- Parameters:
value
- the value to check- Returns:
- true if the provided value is an IP address, otherwise false.
-
isValidIpRange
Checks if the provided value is a representation of an IP address range.- Parameters:
value
- the value to check- Returns:
- true if the provided value is an IP address range, otherwise false.
-
isValidIpAddressOrRange
Checks if the provided value is a representation of an IP address or an IP address range.- Parameters:
value
- the value to check- Returns:
- true if the provided value is an IP address or IP address range, otherwise false.
-