Library stun

A library that implements the basics of the STUN protocol (Session Traversal Utilities for NAT) per RFC3489 and RFC5389. A protocol overview is available at http://en.wikipedia.org/wiki/STUN.

Author:

  • Patrik Karlsson <patrik@cqure.net>

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

Script Arguments

stun.mode

Mode container to use. Supported containers: "modern" (default) or "classic"

Functions

Attribute.new (self, type, data)

creates a new attribute instance

Attribute.parse (data)

parses a string and creates an Attribute instance

Comm.close (self)

closes the connection to the server

Comm.connect (self)

connects the socket to the server

Comm.exch (self, req)

sends the request instance to the server and receives the response

Comm.new (self, host, port, options)

creates a new Comm instance

Comm.recv (self)

receives a response from the server

Comm.send (self, data)

sends a request to the server

Header.new (self, type, trans_id, length)

creates a new instance of Header

Header.parse (data)

parses an opaque string and creates a new Header instance

Helper.close (self)

closes the connection to the server

Helper.connect (self)

connects to the server

Helper.getExternalAddress (self)

Gets the external public IP

Helper.getVersion (self)

Gets the server version if it was returned by the server

Helper.new (self, host, port, options, mode)

creates a new Helper instance

Request.Bind.new (self, trans_id)

Creates a new Bind request

Response.Bind.new (self, trans_id)

creates a new instance of the Bind response

Response.Bind.parse (data)

parses a raw string and creates a new Bind instance

Functions

Attribute.new (self, type, data)

creates a new attribute instance

Parameters

self
 
type
number containing the attribute type
data
string containing the attribute value

Return value:

instance of attribute
Attribute.parse (data)

parses a string and creates an Attribute instance

Parameters

data
string containing the raw attribute

Return value:

new attribute instance
Comm.close (self)

closes the connection to the server

Parameters

self
 

Return values:

  1. status true on success, false on failure
  2. err string containing an error message, if status is false
Comm.connect (self)

connects the socket to the server

Parameters

self
 

Return values:

  1. status true on success, false on failure
  2. err string containing an error message, if status is false
Comm.exch (self, req)

sends the request instance to the server and receives the response

Parameters

self
 
req
request class instance

Return values:

  1. status true on success, false on failure
  2. response containing a response instance, or err string containing an error message, if status is false
Comm.new (self, host, port, options)

creates a new Comm instance

Parameters

self
 
host
table
port
table
options
table, currently supporting: timeout - socket timeout in ms.

Return value:

new instance of Comm
Comm.recv (self)

receives a response from the server

Parameters

self
 

Return values:

  1. status true on success, false on failure
  2. response containing a response instance, or err string containing an error message, if status is false
Comm.send (self, data)

sends a request to the server

Parameters

self
 
data
 

Return values:

  1. status true on success, false on failure
  2. err string containing an error message, if status is false
Header.new (self, type, trans_id, length)

creates a new instance of Header

Parameters

self
 
type
number the request/response type
trans_id
string the 128-bit transaction id
length
number the packet length

Return value:

new instance of Header
Header.parse (data)

parses an opaque string and creates a new Header instance

Parameters

data
opaque string

Return value:

new instance of Header
Helper.close (self)

closes the connection to the server

Parameters

self
 

Return values:

  1. status true on success, false on failure
  2. err string containing an error message, if status is false
Helper.connect (self)

connects to the server

Parameters

self
 

Return values:

  1. status true on success, false on failure
  2. err string containing an error message, if status is false
Helper.getExternalAddress (self)

Gets the external public IP

Parameters

self
 

Return values:

  1. status true on success, false on failure
  2. result containing the IP as string
Helper.getVersion (self)

Gets the server version if it was returned by the server

Parameters

self
 

Return values:

  1. status true on success, false on failure
  2. version string containing the server product and version
Helper.new (self, host, port, options, mode)

creates a new Helper instance

Parameters

self
 
host
table
port
table
options
table, currently supporting: timeout - socket timeout in ms.
mode
containing the mode container. Supported containers: "modern" (default) or "classic"

Return value:

o new instance of Helper
Request.Bind.new (self, trans_id)

Creates a new Bind request

Parameters

self
 
trans_id
string containing the 128 bit transaction ID

Return value:

new instance of the Bind request
Response.Bind.new (self, trans_id)

creates a new instance of the Bind response

Parameters

self
 
trans_id
string containing the 128 bit transaction id

Return value:

new Bind instance
Response.Bind.parse (data)

parses a raw string and creates a new Bind instance

Parameters

data
string containing the raw data

Return value:

a new Bind instance