OWL ITS + 탐지시스템(인터넷 진흥원)
이민희
2022-03-17 916a3cbabe4e50062fce61ff6f2f5d46c05dfbd1
src/main/java/kr/wisestone/owl/util/ConvertUtil.java
@@ -3,11 +3,12 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import kr.wisestone.owl.constant.MsgConstants;
import kr.wisestone.owl.constant.Regular;
import kr.wisestone.owl.exception.OwlRuntimeException;
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);
@@ -357,7 +359,9 @@
                }
            }
        } catch (Exception e) {
            LOGGER.error("fieldName : " + fieldName, e);
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("fieldName : " + fieldName, e);
            }
            return false;
        }
@@ -556,4 +560,44 @@
        return  list.toArray(new String[list.size()]);
    }
    /**
     * ip주소 long으로 변환
     * @param ipAddress String
     * @return long
     */
    public static long ipToLong(String ipAddress) {
        long result = 0;
        if (!StringUtils.isEmpty(ipAddress) && !Pattern.matches(Regular.IP, 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);
            }
        }
        return result;
    }
    /**
     * 콤마로 구분된 문자열을 IP 배열로 변환
     * @param ipAddressList 콤마로 구분된 IP 문자열
     * @return 정수로 변환한 배열
     */
    public static List<Long> ipToLongs(String ipAddressList) {
        if (!StringUtils.isEmpty(ipAddressList)) {
            String[] split = ipAddressList.split(CommonUtil.COMMA);
            List<Long> longs = Lists.newArrayList();
            for (String str : split) {
                longs.add(ipToLong(str));
            }
            return longs;
        }
        return null;
    }
}