IP Range导入自动格式转换0.0.0.1-2转换为0.0.0.1-0.0.0.2

This commit is contained in:
wangxin
2018-10-30 15:59:56 +08:00
parent 5efc61733a
commit 993392f8c5
3 changed files with 21 additions and 0 deletions

View File

@@ -62,6 +62,8 @@ public final class Constants {
public static final String IPV4_IP_SUBNET_REGEXP=Configurations.getStringProperty("ipv4_ip_subnet_regexp", "*"); public static final String IPV4_IP_SUBNET_REGEXP=Configurations.getStringProperty("ipv4_ip_subnet_regexp", "*");
public static final String IPV6_IP_SUBNET_REGEXP=Configurations.getStringProperty("ipv6_ip_subnet_regexp", "*"); public static final String IPV6_IP_SUBNET_REGEXP=Configurations.getStringProperty("ipv6_ip_subnet_regexp", "*");
public static final String IPV4_IP_RANGE_REGEXP=Configurations.getStringProperty("ipv4_ip_range_regexp", "*"); public static final String IPV4_IP_RANGE_REGEXP=Configurations.getStringProperty("ipv4_ip_range_regexp", "*");
//0.0.0.1-2这种格式
public static final String IPV4_IP_RANGE_REGEXP_NEW=Configurations.getStringProperty("ipv4_ip_range_regexp_new", "*");
public static final String IPV6_IP_RANGE_REGEXP=Configurations.getStringProperty("ipv6_ip_range_regexp", "*"); public static final String IPV6_IP_RANGE_REGEXP=Configurations.getStringProperty("ipv6_ip_range_regexp", "*");
public static final String IPV4_IP_REGEXP=Configurations.getStringProperty("ipv4_ip_regexp", "*"); public static final String IPV4_IP_REGEXP=Configurations.getStringProperty("ipv4_ip_regexp", "*");
public static final String IPV6_IP_REGEXP=Configurations.getStringProperty("ipv6_ip_regexp", "*"); public static final String IPV6_IP_REGEXP=Configurations.getStringProperty("ipv6_ip_regexp", "*");

View File

@@ -1480,11 +1480,28 @@ public class BaseController {
boolean destIpEmpty = false; boolean destIpEmpty = false;
boolean srcPortEmpty = false; boolean srcPortEmpty = false;
boolean destPortEmpty = false; boolean destPortEmpty = false;
Pattern ipv4IpRangeRegexpNew = Pattern.compile(Constants.IPV4_IP_RANGE_REGEXP_NEW);
if (StringUtil.isEmpty(baseIpCfg.getSrcIpAddress())) { if (StringUtil.isEmpty(baseIpCfg.getSrcIpAddress())) {
srcIpEmpty = true; srcIpEmpty = true;
}else {
//处理0.0.0.1-2这种格式转换为0.0.0.1-0.0.0.2
Matcher m=ipv4IpRangeRegexpNew.matcher(baseIpCfg.getSrcIpAddress());
if(m.matches()) {
String prefix=baseIpCfg.getSrcIpAddress().split("-")[0];
String subfix=baseIpCfg.getSrcIpAddress().split("-")[1];
baseIpCfg.setSrcIpAddress(prefix+"-"+prefix.substring(0, prefix.lastIndexOf(".")+1)+subfix);
}
} }
if (StringUtil.isEmpty(baseIpCfg.getDestIpAddress())) { if (StringUtil.isEmpty(baseIpCfg.getDestIpAddress())) {
destIpEmpty = true; destIpEmpty = true;
}else {
//处理0.0.0.1-2这种格式转换为0.0.0.1-0.0.0.2
Matcher m=ipv4IpRangeRegexpNew.matcher(baseIpCfg.getDestIpAddress());
if(m.matches()) {
String prefix=baseIpCfg.getDestIpAddress().split("-")[0];
String subfix=baseIpCfg.getDestIpAddress().split("-")[1];
baseIpCfg.setDestIpAddress(prefix+"-"+prefix.substring(0, prefix.lastIndexOf(".")+1)+subfix);
}
} }
if (StringUtil.isEmpty(baseIpCfg.getSrcPort())) { if (StringUtil.isEmpty(baseIpCfg.getSrcPort())) {
srcPortEmpty = true; srcPortEmpty = true;

View File

@@ -539,3 +539,5 @@ cert_file_path=/home/cert/
cert_validate_file=x509 cert_validate_file=x509
#证书校验成功的关键信息 #证书校验成功的关键信息
cert_validate_success_info=Successful cert_validate_success_info=Successful
#ipv4 range新格式0.0.0.1-2
ipv4_ip_range_regexp_new=^(0|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\.(0|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\.(0|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\.(0|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)-(0|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$