Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public static boolean isValidIPv6Cidr(String cidr) {

public static boolean isIPInRange(String ip, String cidr) {
try {
if (StringUtils.equals(cidr, "*") || StringUtils.equals(cidr, "0.0.0.0")
|| StringUtils.equals(cidr, "0.0.0.0/0") || StringUtils.equals(cidr, "::")
|| StringUtils.equals(cidr, "::/0")) {
return true;
}
String[] parts = cidr.split(SLASH);
if (parts.length == 1) {
return StringUtils.equals(ip, cidr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ public void isIPInRange() {
assert IPAddressUtils.isIPInRange(ipv6Address, ipv6Cidr);
}

@Test
public void isIPInRangeWildcard() {
assert IPAddressUtils.isIPInRange("192.168.1.10", "0.0.0.0");
assert IPAddressUtils.isIPInRange("10.0.0.1", "0.0.0.0/0");
assert IPAddressUtils.isIPInRange("192.168.1.10", "*");
assert IPAddressUtils.isIPInRange("2001:0db8:85a3::8a2e:0370:7334", "::");
assert IPAddressUtils.isIPInRange("2001:0db8:85a3::8a2e:0370:7334", "::/0");
assert IPAddressUtils.isIPInRange("192.168.1.10", "::/0");
assert IPAddressUtils.isIPInRange("2001:0db8::1", "0.0.0.0/0");
}

@Test
public void isValidCidr() {
String ipv4Cidr = "192.168.1.0/24";
Expand Down