Book Image

Mastering the Nmap Scripting Engine

By : Paulino Calderon
Book Image

Mastering the Nmap Scripting Engine

By: Paulino Calderon

Overview of this book

Table of Contents (23 chapters)
Mastering the Nmap Scripting Engine
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Scan Phases
Script Categories
Nmap Options Mind Map
References
Index

Printing verbosity messages


If you hate scripts that just seem to stop working because of a lack of information in the output, then you need to include verbosity messages in your scripts. The purpose of these messages is to inform users of what is going on behind the scenes while your script does its work. Verbosity messages should be clear and concise while explaining the progress of the current task.

The stdnse library offers the verbose() function to print these verbose messages:

  • level: This is the level of verbosity needed to print the message. The number can be from 1 to 9 but, in practice, most developers use up to level 3 only.

  • fmt: This outputs a properly formatted message.

  • : This is used to format arguments.

For example, to print a verbose message only when the verbosity level is higher than 2, we use the following code:

      local stdnse = require "stdnse"
      …
     for i,v in pairs(arr) do
        stdnse.verbose(2, "ID %d - %s", i, v)
     end

If you need to obtain the verbosity...