Package org.kiwiproject.net
Class CidrRange
- java.lang.Object
-
- org.kiwiproject.net.CidrRange
-
public class CidrRange extends Object
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.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetBroadcastAddress()Returns the broadcast address for the CIDR.StringgetNetworkAddress()Returns the network address for the CIDR.booleanisInRange(String ipAddress)Checks 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 Detail
-
CidrRange
public CidrRange(String cidr)
Creates a new instance of KiwiCidrs parsing the given CIDR.- Parameters:
cidr- the CIDR to use for this instance.
-
-
Method Detail
-
getNetworkAddress
public String 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
public String 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
public boolean isInRange(String ipAddress)
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
public boolean isInRange(InetAddress address)
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
-
-