Nmap scans are divided into several phases but NSE is only involved in three of them: pre-scanning, script scanning, and post-scanning. The execution rule defined by a function in the NSE script determines whether it runs in any of those phases.
To learn more about the phases of Nmap scans, check out Appendix A, Scan Phases.
NSE scripts can have one of four different types of execution rule:
Let's review some examples of these different script rules. This will also help you learn to debug scripts for those times when you run into problems:
prerule(): The following is a snippet from the
targets-sniffer.nseNSE script. It illustrates how we can use a
prerulefunction to check whether ...