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

Flow control structures


Some classic control structures are implemented in Lua, such as the if-then conditional statements, a few different loop types, and the break and continue functions. Let's review these structures briefly. The objective of the following sections is to get you familiar with the syntax used in this language.

Conditional statements – if-then, else, and elseif

The if-then conditional statement evaluates an expression and executes a block of code if the expression is true. It uses the following syntax:

if status.body then
  --Do something
end

Lua also supports an else-if conditional statement with the elseif keyword:

if status.code == 200 then
  --Do something
elseif status.code == 301 then
  --Do something else
end

An else statement does not need any expression to be evaluated:

if status.code == 200 then
  --Do something
elseif status.code == 301 then
  --Do something else
else
  --If no conditions are true…
end

Loops – while

The while loop structure is very similar to what we...