From 9928f1df9651aa388452cbb396cf3a3d5da1dd22 Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Wed, 19 Feb 2014 17:51:08 +0000 Subject: [PATCH] ENH: Allow 255.255.255.0 style mask for ignoreip --- server/filter.py | 3 +++ testcases/filtertestcase.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/server/filter.py b/server/filter.py index 840c5316..0e5f9ecb 100644 --- a/server/filter.py +++ b/server/filter.py @@ -288,6 +288,9 @@ class Filter(JailThread): # IP address without CIDR mask if len(s) == 1: s.insert(1, '32') + elif "." in s[1]: # 255.255.255.0 style mask + s[1] = len(re.search( + "(?<=b)1+", bin(DNSUtils.addr2bin(s[1]))).group()) s[1] = long(s[1]) try: a = DNSUtils.cidr(s[0], s[1]) diff --git a/testcases/filtertestcase.py b/testcases/filtertestcase.py index 30397d67..f1a9bcd2 100644 --- a/testcases/filtertestcase.py +++ b/testcases/filtertestcase.py @@ -188,6 +188,15 @@ class IgnoreIP(LogCaptureTestCase): self.assertFalse(self.filter.inIgnoreIPList('192.168.1.255')) self.assertFalse(self.filter.inIgnoreIPList('192.168.0.255')) + def testIgnoreIPMask(self): + self.filter.addIgnoreIP('192.168.1.0/255.255.255.128') + self.assertTrue(self.filter.inIgnoreIPList('192.168.1.0')) + self.assertTrue(self.filter.inIgnoreIPList('192.168.1.1')) + self.assertTrue(self.filter.inIgnoreIPList('192.168.1.127')) + self.assertFalse(self.filter.inIgnoreIPList('192.168.1.128')) + self.assertFalse(self.filter.inIgnoreIPList('192.168.1.255')) + self.assertFalse(self.filter.inIgnoreIPList('192.168.0.255')) + def testIgnoreInProcessLine(self): self.filter.addIgnoreIP('192.168.1.0/25') self.filter.addFailRegex('')