日期:2014-05-19 浏览次数:21061 次
public class CibTest { public static void main(String[] args) { String loc_ip = "192.16.1.8"; boolean loc_result = new CibTest().isAddressInclude(loc_ip); System.out.println(loc_result); } private boolean isAddressInclude(String ip_ipAddr) { try { String loc_ip2 = "192.168.0.1;192.168.1.9"; String[] loc_ipIndex = loc_ip2.split(";"); if(ip_ipAddr == null || "".equals(ip_ipAddr) || (ip_ipAddr.split("[.]").length < 4)) { return false; } String loc_minIp[] = loc_ipIndex[0].split("[.]"); String loc_maxIp[] = loc_ipIndex[1].split("[.]"); String loc_ip[] = ip_ipAddr.split("[.]"); for(int i = 0;i < 4;i++) { if((Integer.parseInt(loc_ip[i]) > Integer.parseInt(loc_maxIp[i])) || (Integer.parseInt(loc_ip[i]) < Integer.parseInt(loc_minIp[i]))) { return false; } } return true; } catch(Exception ip_exp) { ip_exp.printStackTrace(); return false; } } }