增强IP工具类

beetlsql3-dev
Mlxa0324 2 years ago
parent 046a63793a
commit 2cd0f7d0c7

@ -119,15 +119,32 @@ public class IpUtils {
* IP
*
*
* @param ipAddressList x.x.x.x-x.x.x.x,x.x.x.x-x.x.x.xIP
* @param ipRangeAddressList x.x.x.x-x.x.x.x,x.x.x.x-x.x.x.xIP
*/
public static void verifyIpRange(String ipAddressList) {
Assert.notBlank(ipAddressList, "待验证的IP区间不能为空");
for (String ipRange : ipAddressList.split(SEPARATOR)) {
public static void verifyIpRange(String ipRangeAddressList) {
Assert.notBlank(ipRangeAddressList, "待验证的IP区间不能为空");
for (String ipRange : ipRangeAddressList.split(SEPARATOR)) {
// IP区间的正则
String reg = "^((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}" +
"-((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}$";
Assert.isTrue(ReUtil.isMatch(reg, ipRange),
() -> new PlatformException("ipAddressList 参数格式化错误支持格式x.x.x.x-x.x.x.x,x.x.x.x-x.x.x.x"));
() -> new PlatformException("ipRangeAddressList 参数格式化错误支持格式x.x.x.x-x.x.x.x,x.x.x.x-x.x.x.x"));
}
}
/**
* IP
*
*
* @param ipAddressList x.x.x.x IP
*/
public static void verifyIp(String ipAddressList) {
Assert.notBlank(ipAddressList, "待验证的IP不能为空");
for (String ip : ipAddressList.split(SEPARATOR)) {
// 单IP的正则
String reg = "^((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}$";
Assert.isTrue(ReUtil.isMatch(reg, ip),
() -> new PlatformException("ipAddressList 参数格式化错误支持格式x.x.x.x,x.x.x.x"));
}
}

Loading…
Cancel
Save