MonitorHelper.java 1.04 KB
package com.yoho.rfid.helper;

import com.yoho.rfid.model.IpV4Host;
import com.yoho.rfid.model.SystemConfig;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * Created by chenchao on 2017/11/9.
 */
public class MonitorHelper {

    public static final boolean isWhiteIp(String ip, List<IpV4Host> whiteList){
        String[] segments = StringUtils.split(ip, "\\.");
        for (IpV4Host ipV4Host : whiteList) {
            boolean flag = String.valueOf(ipV4Host.getSegment1()).equals(segments[0]);
            if (flag) {
                return true;
            }
        }
        return false;
    }


    public static void main(String[] args) {
        boolean result = MonitorHelper.isWhiteIp("172.16.6.61", SystemConfig.getInstance().getHostWhiteList());
        System.out.println("172.16.6.61,result is "+ result);

        result = MonitorHelper.isWhiteIp("192.16.6.61", SystemConfig.getInstance().getHostWhiteList());
        System.out.println("192.16.6.61 ,result is "+ result);
    }
}