From 74a750a8558e0d81b013648c801c51964dfb823e Mon Sep 17 00:00:00 2001 From: dmiller Date: Thu, 13 Sep 2012 20:24:18 +0000 Subject: [PATCH] Allow negative matching in Zenmap filters nmap-dev thread: http://seclists.org/nmap-dev/2012/q3/788 Host filter and others can now take things like "os:!linux" to match hosts without Linux OS. --- zenmap/zenmapCore/NetworkInventory.py | 6 +++++- zenmap/zenmapCore/SearchResult.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/zenmap/zenmapCore/NetworkInventory.py b/zenmap/zenmapCore/NetworkInventory.py index dc286626f..4fc0be679 100644 --- a/zenmap/zenmapCore/NetworkInventory.py +++ b/zenmap/zenmapCore/NetworkInventory.py @@ -445,7 +445,11 @@ class FilteredNetworkInventory(NetworkInventory): """A helper function that calls the matching function for the given operator and each of its arguments.""" for arg in args: - if not self.__getattribute__("match_%s" % operator)(host, arg): + positive = True + if arg != "" and arg[0] == "!": + arg = arg[1:] + positive = False + if positive != self.__getattribute__("match_%s" % operator)(host, arg): # No match for this operator return False else: diff --git a/zenmap/zenmapCore/SearchResult.py b/zenmap/zenmapCore/SearchResult.py index 26fd6d885..1a1d22a92 100644 --- a/zenmap/zenmapCore/SearchResult.py +++ b/zenmap/zenmapCore/SearchResult.py @@ -200,7 +200,11 @@ class SearchResult(object): """A helper function that calls the matching function for the given operator and each of its arguments.""" for arg in args: - if not self.__getattribute__("match_%s" % operator)(arg): + positive = True + if arg != "" and arg[0] == "!": + arg = arg[1:] + positive = False + if positive != self.__getattribute__("match_%s" % operator)(arg): # No match for this operator return False else: