Library comm
Common communication functions for network discovery tasks like banner grabbing and data exchange.
The functions in this module return values appropriate for use with
exception handling via nmap.new_try.
These functions may be passed a table of options, but it's not required. The
keys for the options table are "bytes", "lines",
"proto", and "timeout". "bytes" sets
a minimum number of bytes to read. "lines" does the same for
lines. "proto" sets the protocol to communicate with,
defaulting to "tcp" if not provided. "timeout"
sets the socket timeout (see the socket function set_timeout
for details).
If both "bytes" and "lines" are provided,
"lines" takes precedence. If neither are given, the functions
read as many bytes as possible.
Author:
| Kris Katterjohn 04/2008 |
Copyright© Same as Nmap--See http://nmap.org/book/man-legal.html
Source: http://nmap.org/svn/nselib/comm.lua
Functions
| exchange (host, port, data, opts) |
This function connects to the specified port number on the specified host, sends data, then waits for and returns the response, if any. |
| get_banner (host, port, opts) |
This function simply connects to the specified port number on the specified host and returns any data received. |
| tryssl (host, port, data, opts) |
This function tries to open a connection based on the best option about which is the correct protocol |
Functions
- exchange (host, port, data, opts)
-
This function connects to the specified port number on the specified host, sends data, then waits for and returns the response, if any.
The first return value is true to signal success or false to signal failure. On success the second return value is the response from the remote host. On failure the second return value is an error message.
Parameters
- host: The host to connect to.
- port: The port on the host.
- data: The data to send initially.
- opts: The options. See the module description.
Return values:
- Status (true or false).
- Data (if status is true) or error string (if status is false).
- get_banner (host, port, opts)
-
This function simply connects to the specified port number on the specified host and returns any data received.
The first return value is true to signal success or false to signal failure. On success the second return value is the response from the remote host. On failure the second return value is an error message.
Parameters
- host: The host to connect to.
- port: The port on the host.
- opts: The options. See the module description.
Return values:
- Status (true or false).
- Data (if status is true) or error string (if status is false).
- tryssl (host, port, data, opts)
-
This function tries to open a connection based on the best option about which is the correct protocol
If the best option fails, the function tries the other option
This function allows writing nse scripts in a way that the API will take care of ssl issues, making failure detection transparent to the programmer
Parameters
- host: The host table
- port: The port table
- data: The first data payload of the connection
- opts: Options, such as timeout
Return values:
- sd The socket descriptor
- response The response received for the payload
- correctOpt Correct option for connection guess
- earlyResp If opt recv_before is true, returns the value of the first receive (before sending data)


