Library datafiles

Read and parse some of Nmap's data files: nmap-protocols, nmap-rpc, nmap-services, and nmap-mac-prefixes.

The functions in this module return values appropriate for use with exception handling via nmap.new_try. On success, they return true and the function result. On failure, they return false and an error message.

Authors:

  • Kris Katterjohn 03/2008
  • jah 08/2008

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

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

Functions

get_array (lines, v_pattern)

Return an array-like table of values captured from each line.

get_assoc_array (lines, i_pattern, v_pattern)

Return a table of index-value pairs captured from each line.

parse_file (filename, ...)

Read and parse a generic data file. The other parse functions are defined in terms of this one.

parse_lines (lines, data_struct)

Generic parsing of an array of strings.

parse_mac_prefixes ()

Read and parse nmap-mac-prefixes.

parse_protocols ()

Read and parse nmap-protocols.

parse_rpc ()

Read and parse nmap-rpc.

parse_services (protocol)

Read and parse nmap-services.

read_from_file (file)

Read a file, line by line, into a table.

Tables

common_files

Capture patterns for common data files, indexed by filename.

Functions

get_array (lines, v_pattern)

Return an array-like table of values captured from each line.

Parameters

lines
Table of strings containing the lines to process.
v_pattern
Pattern to use on the lines to produce the value for the array.
get_assoc_array (lines, i_pattern, v_pattern)

Return a table of index-value pairs captured from each line.

Parameters

lines
Table of strings containing the lines to process.
i_pattern
Pattern to use on the lines to produce the key for the associative array.
v_pattern
Pattern to use on the lines to produce the value for the associative array.
parse_file (filename, ...)

Read and parse a generic data file. The other parse functions are defined in terms of this one.

If filename is a key in common_files, use the corresponding capture pattern. Otherwise the second argument must be a table of the kind taken by parse_lines.

Parameters

filename
Name of the file to parse.
...
A table of capture patterns.

Return values:

  1. Boolean status, false on failure
  2. A table whose structure mirrors that of the capture table, filled in with captured values.
parse_lines (lines, data_struct)

Generic parsing of an array of strings.

Parameters

lines
An array of strings to operate on.
data_struct
A table containing capture patterns to be applied to each string in the array. A capture will be applied to each string using string.match and may also be enclosed within a table or a function. If a function, it must accept a string as its parameter and should return one value derived from that string.

Return value:

A table whose structure mirrors that of the capture table, filled in with captured values.
parse_mac_prefixes ()

Read and parse nmap-mac-prefixes.

On success, return true and a table mapping 3 byte MAC prefixes to manufacturer names.

Return values:

  1. Status (true or false).
  2. Table (if status is true) or error string (if status is false).

See also:

parse_protocols ()

Read and parse nmap-protocols.

On success, return true and a table mapping protocol numbers to protocol names.

Return values:

  1. Status (true or false).
  2. Table (if status is true) or error string (if status is false).

See also:

parse_rpc ()

Read and parse nmap-rpc.

On success, return true and a table mapping RPC numbers to RPC names.

Return values:

  1. Status (true or false).
  2. Table (if status is true) or error string (if status is false).

See also:

parse_services (protocol)

Read and parse nmap-services.

On success, return true and a table containing two subtables, indexed by the keys "tcp" and "udp". The tcp subtable maps TCP port numbers to service names, and the udp subtable is the same for UDP. You can pass "tcp" or "udp" as an argument to parse_services to get only one of the results tables.

Parameters

protocol
The protocol table to return ("tcp" or "udp").

Return values:

  1. Status (true or false).
  2. Table (if status is true) or error string (if status is false).

See also:

read_from_file (file)

Read a file, line by line, into a table.

Parameters

file
String with the name of the file to read.

Return values:

  1. Status (true or false).
  2. Array of lines read from the file (if status is true) or error message (if status is false).

Tables

common_files

Capture patterns for common data files, indexed by filename.