Triggering functions – the rule
The rule or portrule section of an Nmap script determines when the action should take place (which we'll cover in the next section). It's important to define this clearly so that we are confident that our script will run every time we need it to (based on port number and version). There are two ways to accomplish this type of rule: standard portrule documentation, and a helper library built in the NSE called shortport.
Defining a rule is actually very simple, depending on what we're looking for. In the case of our robots.txt detection script (aptly named robots.nse), we just want to trigger on port 80 to see if robots.txt exists.
If we were writing a production script, rather than a proof of concept, it would probably ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access