From 96df029f43c57c46dcd3d2cfa15e02257ed1cb64 Mon Sep 17 00:00:00 2001
From: duandongmei
Date: Sat, 26 Jan 2019 19:41:58 +0600
Subject: [PATCH] =?UTF-8?q?ASN=E5=AE=9A=E6=97=B6=E8=AE=A1=E7=AE=97v4?=
=?UTF-8?q?=E5=92=8Cv6=E7=9A=84IP=E4=B8=AA=E6=95=B0=EF=BC=9B=20=E7=95=8C?=
=?UTF-8?q?=E9=9D=A2=E5=B1=95=E7=A4=BAASNIPv4=E5=92=8Cv6=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/com/nis/domain/Nets.java | 31 +
.../java/com/nis/util/ConfigDictUtils.java | 35 +
src/main/java/com/nis/util/IPUtil.java | 759 ++++++++++++++++++
.../nis/web/dao/basics/AsnGroupInfoDao.java | 2 +
.../nis/web/dao/basics/AsnGroupInfoDao.xml | 6 +
.../com/nis/web/dao/basics/AsnIpCfgDao.java | 1 +
.../com/nis/web/dao/basics/AsnIpCfgDao.xml | 6 +
.../com/nis/web/task/StatisticASNIpNumer.java | 134 ++++
.../resources/messages/message_en.properties | 4 +-
.../resources/messages/message_ru.properties | 4 +-
.../messages/message_zh_CN.properties | 4 +-
src/main/resources/spring-mvc.xml | 14 +-
src/main/webapp/WEB-INF/tlds/fns.tld | 8 +
.../WEB-INF/views/basics/asnGroupList.jsp | 7 +
.../WEB-INF/views/basics/asnIpCfgList.jsp | 7 +
15 files changed, 1017 insertions(+), 5 deletions(-)
create mode 100644 src/main/java/com/nis/domain/Nets.java
create mode 100644 src/main/java/com/nis/util/IPUtil.java
create mode 100644 src/main/java/com/nis/web/task/StatisticASNIpNumer.java
diff --git a/src/main/java/com/nis/domain/Nets.java b/src/main/java/com/nis/domain/Nets.java
new file mode 100644
index 000000000..7c9d2690b
--- /dev/null
+++ b/src/main/java/com/nis/domain/Nets.java
@@ -0,0 +1,31 @@
+package com.nis.domain;
+
+/**
+ * Created by dell on 2018-8-30.
+ */
+public class Nets {
+
+ private String StartIP;
+ private String EndIP;
+ private String NetMask;
+ public String getStartIP() {
+ return StartIP;
+ }
+ public void setStartIP(String startIP) {
+ StartIP = startIP;
+ }
+ public String getEndIP() {
+ return EndIP;
+ }
+ public void setEndIP(String endIP) {
+ EndIP = endIP;
+ }
+ public String getNetMask() {
+ return NetMask;
+ }
+ public void setNetMask(String netMask) {
+ NetMask = netMask;
+ }
+
+
+}
diff --git a/src/main/java/com/nis/util/ConfigDictUtils.java b/src/main/java/com/nis/util/ConfigDictUtils.java
index dffc42ed2..2c2c656cf 100644
--- a/src/main/java/com/nis/util/ConfigDictUtils.java
+++ b/src/main/java/com/nis/util/ConfigDictUtils.java
@@ -2,6 +2,7 @@ package com.nis.util;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -11,6 +12,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.nis.domain.SysDataDictionaryItem;
import com.nis.domain.SysDataDictionaryName;
+import com.nis.domain.basics.AsnGroupInfo;
import com.nis.domain.basics.ServiceDictInfo;
import com.nis.domain.basics.SysDictInfo;
import com.nis.domain.configuration.BaseStringCfg;
@@ -18,6 +20,7 @@ import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.configuration.PxyObjTrustedCaCrl;
import com.nis.domain.specific.SpecificServiceCfg;
import com.nis.web.dao.SysDictDao;
+import com.nis.web.dao.basics.AsnGroupInfoDao;
import com.nis.web.dao.basics.ServiceDictInfoDao;
import com.nis.web.dao.basics.SysDictInfoDao;
import com.nis.web.dao.configuration.PxyObjKeyringDao;
@@ -41,6 +44,7 @@ public class ConfigDictUtils {
private final static SpecificServiceCfgDao specificServiceCfgDao = SpringContextHolder.getBean(SpecificServiceCfgDao.class);
private final static WebsiteCfgDao websiteCfgDao = SpringContextHolder.getBean(WebsiteCfgDao.class);
private final static PxyObjKeyringDao pxyObjKeyringDao = SpringContextHolder.getBean(PxyObjKeyringDao.class);
+ private final static AsnGroupInfoDao asnGroupInfoDao = SpringContextHolder.getBean(AsnGroupInfoDao.class);
/**
* 根据主键查询配置详情
@@ -203,4 +207,35 @@ public class ConfigDictUtils {
}
return crlFIle;
}
+ /**
+ * 根据compileId获取配置内容
+ * @param compileId
+ * @return
+ */
+ public static List getASNIPNum(Integer groupId ) {
+ List ipNum=new ArrayList<>();
+ ipNum.add(0, 0);
+ ipNum.add(1, 0);
+ try {
+ if(!StringUtil.isEmpty(groupId)){
+ List
+ * 例子说明:
+ * @param ip ip字符
+ * @return true ip符合验证规则, false ip不符合验证规则.
+ */
+ public static boolean isIP(String ip) {
+ if (ip == null) {
+ return false;
+ }
+ Matcher mat = IPV4Pattern.matcher(ip);
+ return mat.matches();
+ }
+
+
+ public static boolean isIPv6StdAddress(final String input) {
+ return IPV6_STD_PATTERN.matcher(input).matches();
+ }
+
+ public static boolean isIPv6HexCompressedAddress(final String input) {
+ return IPV6_HEX_COMPRESSED_PATTERN.matcher(input).matches();
+ }
+
+ public static boolean isIPv6Address(final String input) {
+ return isIPv6StdAddress(input) || isIPv6HexCompressedAddress(input);
+ }
+
+ /**
+ *
+ * 在web方式下获取客户端IP地址.
+ *
+ * 使用该方法,需要在有javaee.jar扩展包前提下.
+ *
+ * @param request HttpServletRequest请求对象
+ * @return 返回字符串IP地址
+ */
+ public static String getIpAddr(HttpServletRequest request) {
+ String ip = request.getHeader("X-Forwarded-For");
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("Proxy-Client-IP");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("WL-Proxy-Client-IP");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("HTTP_CLIENT_IP");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getRemoteAddr();
+ }
+ return ip;
+ }
+
+
+ /**
+ *
+ * 验证mask是否符合规则.给定字符串,判断是否符合正则验证的mask格式.
+ * 例子说明:
+ * @param mask mask字符
+ * @return true mask符合验证规则, false mask不符合验证规则.
+ */
+ public static boolean isMask(String mask) {
+ if (mask == null) {
+ return false;
+ }
+ if(!isIP(mask)){
+ return false;
+ }
+ String[] ips = mask.split("\\.");
+ String binaryVal = "";
+ for (int i = 0; i < ips.length; i++)
+ {
+ String binaryStr = Integer.toBinaryString(Integer.parseInt(ips[i]));
+ Integer times = 8 - binaryStr.length();
+
+ for(int j = 0; j < times; j++)
+ {
+ binaryStr = "0" + binaryStr;
+ }
+ binaryVal += binaryStr;
+ }
+ if(binaryVal.indexOf("01")!=-1){
+ return false;
+ }
+ return true;
+ }
+
+
+ /**
+ *
+ * 将IP进制转换成十进制网络字节序
+ *
+ * IP是一个字符串,符合IP的规则(0-255).(0-255).(0-255).(0-255).
+ * 将ip转换成长整型的原因是:处理时间类型简单;入库节省空间,查询提高效率.
+ *
+ *
+ * IpUtil.getIpDesimal("192.168.1.1") = 3232235777
+ * IpUtil.getIpDesimal("192.168.1.256") = -1 //不符合Ip规则
+ *
+ * @see #getIpString(String)
+ * @param ip 符合IP规则的字符串
+ * @return -1 验证ip不合法,ip 计算ip返回长整型.
+ */
+ public static long getIpDesimal(String ip) {
+ long ip10 = 0;
+ if (!isIP(ip)) {
+ return -1; // ip 不合法
+ }
+ String[] ss = ip.trim().split("\\.");
+ for (int i = 0; i < 4; i++) {
+ ip10 += Math.pow(256, i) * Long.parseLong(ss[i]);
+ }
+
+ return ip10;
+ }
+
+
+ /**
+ *
+ * 将IP进制转换成十进制主机字节序
+ *
+ * IP是一个字符串,符合IP的规则(0-255).(0-255).(0-255).(0-255).
+ * 将ip转换成长整型的原因是:处理时间类型简单;入库节省空间,查询提高效率.
+ *
+ *
+ * IpUtil.getIpHostDesimal("192.168.1.1") = 3232235777
+ * IpUtil.getIpHostDesimal("192.168.1.256") = -1 //不符合Ip规则
+ *
+ * @see #getIpString(String)
+ * @param ip 符合IP规则的字符串
+ * @return -1 验证ip不合法,ip 计算ip返回长整型.
+ */
+
+ public static long getIpHostDesimal(String ip) {
+ long ip10 = 0;
+ if (!isIP(ip)) {
+ return -1; // ip 不合法
+ }
+ String[] ss = ip.trim().split("\\.");
+ for (int i = 0; i < 4; i++) {
+ ip10 += Math.pow(256, 3 - i) * Long.parseLong(ss[i]);
+ }
+
+ return ip10;
+ }
+
+
+
+ /**
+ *
+ * 获取IP/mask 包含IP数量,适合完整IPw网段
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ * @param ip 符合IP规则的字符串
+ * @param mask 掩码格式
+ * @return -1 验证ip不合法,ip 计算ip返回长整型.
+ */
+ public static long getIpNum(String ip, int mask) {
+ long num = 0;
+
+ if (isIP(ip)) {
+ String endIp = getEndIP(ip, mask);
+ num = getIpHostDesimal(endIp) - getIpHostDesimal(ip) +1;
+
+ } else {
+ throw new IllegalArgumentException("所传入的IP地址不符合IPV4规范");
+ }
+
+ return num;
+ }
+
+
+
+
+ // 此方法用于判断数据为空就置为0
+ private static String setStrEmpty(String str) {
+ if ("".equals(str) || str == null) {
+ str = "0";
+ }
+ return str;
+ }
+
+
+ private static String toString(byte[] address) {
+ StringWriter sw = new StringWriter(16);
+ sw.write(Integer.toString(address[0]&0xFF));
+ for(int i=1;i {
void deleteAll();
void insertWithId(AsnGroupInfo asnGroupInfo);
void insertWithoutId(AsnGroupInfo asnGroupInfo);
+ void updateIpNum(@Param("v4Num")long v4Num,@Param("v6Num")long v6Num,@Param("groupId")Integer groupId);
+ List