Library target

Utility functions to add new discovered targets to Nmap scan queue.

The library lets scripts to add new discovered targets to Nmap scan queue. Only scripts that run in the script pre-scanning phase (prerule) and the script scanning phase (hostrule and portrule) are able to add new targets. Post-scanning scripts (postrule) are not allowed to add new targets.

Copyright © Same as Nmap--See https://nmap.org/book/man-legal.html

Source: https://svn.nmap.org/nmap/nselib/target.lua

Script Arguments

newtargets

If specified, lets NSE scripts add new targets.

max-newtargets

Sets the number of the maximum allowed new targets. If set to 0 or less then there is no limit. The default value is 0.

Functions

add (..., targets)

Adds the passed arguments to the Nmap scan queue.

Functions

add (..., targets)

Adds the passed arguments to the Nmap scan queue.

Only prerule, portrule and hostrule scripts can add new targets.

Parameters

...
 
targets
A variable number of targets. Target is a string that represents an IP or a Hostname. If this function is called without target arguments then it will return true and the number of pending targets (waiting to be scanned).

Usage:

local status, err = target.add("192.168.1.1")
local status, err = target.add("192.168.1.1","192.168.1.2",...)
local status, err = target.add("scanme.nmap.org","192.168.1.1",...)
local status, err = target.add(table.unpack(array_of_targets))
local status, pending_targets = target.add()

Return values:

  1. True if it has been able to add a minimum one target, or False on failures and if no targets were added. If this function is called without target arguments then it will return true.
  2. Number of added targets on success, or a string error message in case of failures. If this function is called without target arguments then it will return the number of targets that are in the queue (waiting to be scanned).