From 34763e08f4b16a9f4ea302dd279f743b0475e21e Mon Sep 17 00:00:00 2001 From: ejlbell Date: Wed, 14 Nov 2007 20:04:45 +0000 Subject: [PATCH] Added support for multiple states in portnumber() rules --- nselib/shortport.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/nselib/shortport.lua b/nselib/shortport.lua index 109de01cf..646876c13 100644 --- a/nselib/shortport.lua +++ b/nselib/shortport.lua @@ -2,9 +2,9 @@ module(..., package.seeall) portnumber = function(port, _proto, _state) - local port_table; - local state = _state or "open" + local port_table, state_table local proto = _proto or "tcp" + local state = _state or {"open"} if(type(port) == "number") then port_table = {port} @@ -12,11 +12,19 @@ portnumber = function(port, _proto, _state) port_table = port end + if(type(state) == "string") then + state_table = {state} + elseif(type(state) == "table") then + state_table = state + end + return function(host, port) - if(port.protocol == proto and port.state == state) then - for _, _port in ipairs(port_table) do - if(port.number == _port) then - return true + for _, state in pairs(state_table) do + if(port.protocol == proto and port.state == state) then + for _, _port in ipairs(port_table) do + if(port.number == _port) then + return true + end end end end