Package org.kiwiproject.net
Class CidrRange
java.lang.Object
org.kiwiproject.net.CidrRange
Small utility to analyze CIDR information. Supports both IPv4 and IPv6.
This utility was copied and enhanced from https://github.com/edazdarevic/CIDRUtils which has not been updated since 2019 and seems to be unmaintained.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the broadcast address for the CIDR.Returns the network address for the CIDR.booleanChecks if a given IP address (as a string) is in the CIDR range.booleanisInRange(InetAddress address) Checks if a given IP address (as anInetAddress) is in the CIDR range.
-
Constructor Details
-
CidrRange
Creates a new instance of KiwiCidrs parsing the given CIDR.- Parameters:
cidr- the CIDR to use for this instance.
-
-
Method Details
-
getNetworkAddress
Returns the network address for the CIDR. For example: 192.168.100.15/24 will return 192.168.100.0.- Returns:
- The network address for the CIDR
-
getBroadcastAddress
Returns the broadcast address for the CIDR. For example: 192.168.100.15/24 will return 192.168.100.255.- Returns:
- The broadcast address for the CIDR
-
isInRange
Checks if a given IP address (as a string) is in the CIDR range.- Parameters:
ipAddress- the IP address to check- Returns:
- true if the IP address is in range, false otherwise
-
isInRange
Checks if a given IP address (as anInetAddress) is in the CIDR range.- Parameters:
address- the IP address to check- Returns:
- true if the IP address is in range, false otherwise
-