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

Including debugging information


Debugging messages can be included in NSE scripts using the debug() function from the stdnse library. These messages are shown only when the debugging level has been set to a value higher than 0:

Debug(level, fmt, …) where
level: Debugging level.
fmt: Format string.
…: Format arguments.

To print a debug message when the debugging level is 1 or higher, we use the following code:

stdnse.debug(1, "Task #%d completed.", id)

The idea behind supporting this function is that we can do things such as printing different levels of information without having to write nested code:

stdnse.debug(1, "Response #%d received.", i)
stdnse.debug(2, "Response status code: %d", req.status)
stdnse.debug(3, "Response body:", req.body)

It is important to provide some debugging information in all your NSE scripts. This helps people figure out why things go wrong and submit bug reports.

Tip

The debugging level of a scan is set using the -d[1-9] option:

$ nmap –d3 --script mybuggyscript &lt...