package com.opensoc.alerts.adapters;

import java.util.Set;

import org.apache.commons.net.util.SubnetUtils;

public class RangeChecker {

	static boolean checkRange(Set<String> CIDR_networks, String ip) {
		boolean in_range = false;
		try {
			for (String network : CIDR_networks) {
				
				System.out.println("Looking at range: " + network + " and ip " + ip);
				SubnetUtils utils = new SubnetUtils(network);
				in_range = utils.getInfo().isInRange(ip);

				if (!in_range)
					return false;
			}
		} catch (Exception e) {
			return false;
		}

		return true;
	}
}

@@ -203,45 +203,8 @@
 ) %7B%0A
-%09%09boolean in_range = false;%0A%09%09try %7B%0A%09
 %09%09fo
@@ -245,17 +245,16 @@
  %7B%0A%09%09%09%09%0A
-%09
 %09%09%09Syste
@@ -318,17 +318,16 @@
  + ip);%0A
-%09
 %09%09%09Subne
@@ -374,20 +374,11 @@
 %0A%09%09%09
-%09in_range = 
+if(
 util
@@ -406,31 +406,65 @@
 (ip)
-;%0A
+) %7B
 %0A%09%09%09%09
-if (!in_
+System.out.println(ip + %22 in 
 range
-)%0A%09
+ %22 + network);%0A
 %09%09%09%09
@@ -466,28 +466,27 @@
 %0A%09%09%09%09return 
-fals
+tru
 e;%0A%09%09%09%7D%0A%09%09%7D 
@@ -488,65 +488,40 @@
 %0A%09%09%7D
- catch (Exception e) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%0A%09%09return tru
+%0A%09%09%0A%09%09//no matches%0A%09%09return fals
 e;%0A%09

fix logic in RangeChecker