O'Reilly logo

Mastering the Nmap Scripting Engine by Paulino Calderón Pale

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exploring environment variables

There are a few environment variables that you need to consider when writing scripts because they will be helpful:

  • SCRIPT_PATH: This returns the absolute path of the running script
  • SCRIPT_NAME: This returns the running script name
  • SCRIPT_TYPE: This returns "prerule", "hostrule", "portrule", or "postrule"

Use the SCRIPT_NAME environment variable instead of hardcoding the name of your script. This way, you won't need to update the script if you end up changing its name. For example, you could use it to read script arguments as follows:

local arg1 = stdnse.get_script_args(SCRIPT_NAME..".arg1")

The stdnse library will be explored later in this chapter. This library contains the get_script_args() function that can be used ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required