diff --git a/fail2ban/client/fail2banregex.py b/fail2ban/client/fail2banregex.py index ea2f3a7f..f99f9f01 100644 --- a/fail2ban/client/fail2banregex.py +++ b/fail2ban/client/fail2banregex.py @@ -126,6 +126,9 @@ Report bugs to https://github.com/fail2ban/fail2ban/issues help="File encoding. Default: system locale"), Option("-r", "--raw", action='store_true', help="Raw hosts, don't resolve dns"), + Option("--usedns", action='store', default=None, + help="DNS specified replacement of tags in regexp " + "('yes' - matches all form of hosts, 'no' - IP addresses only)"), Option("-L", "--maxlines", type=int, default=0, help="maxlines for multi-line regex"), Option("-m", "--journalmatch", @@ -240,6 +243,8 @@ class Fail2banRegex(object): else: self.encoding = PREFER_ENC self.raw = True if opts.raw else False + if opts.usedns: + self._filter.setUseDns(opts.usedns) def decode_line(self, line): return FileContainer.decode_line('', self.encoding, line) diff --git a/fail2ban/tests/fail2banregextestcase.py b/fail2ban/tests/fail2banregextestcase.py index 1d38a58e..0154e5af 100644 --- a/fail2ban/tests/fail2banregextestcase.py +++ b/fail2ban/tests/fail2banregextestcase.py @@ -131,6 +131,15 @@ class Fail2banRegexTest(LogCaptureTestCase): self.assertTrue(fail2banRegex.start(opts, args)) self.assertLogged('Lines: 19 lines, 0 ignored, 16 matched, 3 missed') + def testDirectRE_1raw_noDns(self): + (opts, args, fail2banRegex) = _Fail2banRegex( + "--print-all-matched", "--raw", "--usedns=no", + Fail2banRegexTest.FILENAME_01, + Fail2banRegexTest.RE_00 + ) + self.assertTrue(fail2banRegex.start(opts, args)) + self.assertLogged('Lines: 19 lines, 0 ignored, 13 matched, 6 missed') + def testDirectRE_2(self): (opts, args, fail2banRegex) = _Fail2banRegex( "--print-all-matched",