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:
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 byparse_lines
.Parameters
- filename
- Name of the file to parse.
- ...
- A table of capture patterns.
Return values:
- Boolean status, false on failure
- 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 MAC prefixes to manufacturer names. The whole MAC can also be used as a key, since the table calls an internal Nmap function to do the lookup.
Return values:
- Status (true or false).
- 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:
- Status (true or false).
- 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:
- Status (true or false).
- 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 subtables indexed by the keys "tcp", "udp", and "sctp". You can pass a protocol name as an argument to
parse_services
to get only one of the results tables.Parameters
- protocol
- Optional: The protocol table to return (e.g.
"tcp"
or"udp"
).
Return values:
- Status (true or false).
- 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:
- Status (true or false).
- 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.