OWL ITS + 탐지시스템(인터넷 진흥원)
src/main/java/kr/wisestone/owl/util/ConvertUtil.java
@@ -8,6 +8,7 @@
import kr.wisestone.owl.vo.CompanyFieldVo;
import kr.wisestone.owl.vo.IspFieldVo;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
@@ -17,6 +18,7 @@
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
public class ConvertUtil {
    static final Logger LOGGER = LoggerFactory.getLogger(ConvertUtil.class);
@@ -565,11 +567,18 @@
     */
    public static long ipToLong(String ipAddress) {
        long result = 0;
        String[] ipAddressArr = ipAddress.split("\\.");
        String reg = "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\" +
                        ".(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
        if (!StringUtils.isEmpty(ipAddress) && !Pattern.matches(reg, ipAddress)) {
            return result;
        } else {
            String[] ipAddressArr = ipAddress.split("\\.");
        for (int i=0; i<ipAddressArr.length; i++) {
            result += Integer.parseInt(ipAddressArr[i]) * Math.pow(256, 3-i);
            for (int i=0; i<ipAddressArr.length; i++) {
                result += Integer.parseInt(ipAddressArr[i]) * Math.pow(256, 3-i);
            }
        }
        return result;
    }