Nmap Development mailing list archives

[NSE] Verbosity/debugging info for scripts


From: Kris Katterjohn <katterjohn () gmail com>
Date: Thu, 13 Sep 2007 18:59:42 -0500

Hey everyone!

As far as I know, there is no way for scripts to get Nmap's verbosity or debugging values (o.verbose and o.debugging). I have attached a patch to give this info to scripts and a test script to illustrate it's usage.

nmap.verbosity() gives you the o.verbose value and nmap.debugging() gives you the o.debugging value.

Everything seems to work fine for me, all as expected.

Please give it a try, and let me now what you think! Any suggestions on better names than "nmap.verbosity()" and "nmap.debugging()" are welcome, but these just made the most sense to me.

Thanks,
Kris Katterjohn
Index: nse_nmaplib.cc
===================================================================
--- nse_nmaplib.cc      (revision 5833)
+++ nse_nmaplib.cc      (working copy)
@@ -36,6 +36,8 @@
 static int l_get_port_state(lua_State* l, Target* target, Port* port);
 static int l_set_port_state(lua_State* l, Target* target, Port* port);
 static int l_set_port_version(lua_State* l, Target* target, Port* port);
+static int l_get_verbosity(lua_State *);
+static int l_get_debugging(lua_State *);
 
 int l_clock_ms(lua_State* l);
 
@@ -53,6 +55,8 @@
                {"clock_ms", l_clock_ms},
                {"print_debug_unformatted", l_print_debug_unformatted},
                {"new_try", l_exc_newtry},
+               {"verbosity", l_get_verbosity},
+               {"debugging", l_get_debugging},
                {NULL, NULL} 
        };
 
@@ -486,3 +490,15 @@
        return 1;
 }
 
+static int l_get_verbosity(lua_State *l)
+{
+       lua_pushnumber(l, o.verbose);
+       return 1;
+}
+
+static int l_get_debugging(lua_State *l)
+{
+       lua_pushnumber(l, o.debugging);
+       return 1;
+}
+
id = "test"

author = "me"

description = "testing"

categories = {"safe"}

require "stdnse"

portrule = function(host, port)
        return true
end

action = function(host, port)
        local v = nmap.verbosity()
        local d = nmap.debugging()

        stdnse.print_debug("Verbosity: " .. v)
        stdnse.print_debug("Debugging: " .. d)

        if v > 1 then
                stdnse.print_debug("v > 1 works as expected")
        end

        if d > 5 then
                stdnse.print_debug("d > 5 works as expected")
        end

        return
end


_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org

Current thread: