Library dnssd
Library for supporting DNS Service Discovery
The library supports
- Unicast and Multicast requests
- Decoding responses
- Running requests in parallell using Lua coroutines
The library contains the following classes
Comm
Helper
Comm class using functions with a more descriptive name.
** The purpose of this class is to give developers easy access to some of the common DNS-SD tasks.
Util
Util class contains a number of static functions mainly used to convert data.
The following code snipplet queries all mDNS resolvers on the network for a full list of their supported services and returns the formated output:
local helper = dnssd.Helper:new( ) helper:setMulticast(true) return stdnse.format_output(helper:queryServices())
This next snipplet queries a specific host for the same information:
local helper = dnssd.Helper:new( host, port ) return stdnse.format_output(helper:queryServices())
In order to query for a specific service a string or table with service
names can be passed to the Helper.queryServices method.
Author:
| Patrik Karlsson <patrik@cqure.net> |
Copyright© Same as Nmap--See http://nmap.org/book/man-legal.html
Source: http://nmap.org/svn/nselib/dnssd.lua
Script Arguments
dnssd.services
string or table containing services to query
Functions
| createSvcHostTbl (response) |
Creates a service host table |
| decodeRecords (response, result) |
Decodes a record received from the |
| getRecordType (dtype, response, retAll) |
Gets a record from both the Answer and Additional section |
| getUniqueServices (response) |
Creates a unique list of services |
| ipCompare (a, b) |
Compare function used for sorting IP-addresses |
| new (self, host, port) |
Creates a new helper instance |
| queryAllServices (host, port, multiple) |
Query the mDNS resolvers for a list of their services |
| queryService (host, port, svc, multiple, svcresponse) |
Send a query for a particular service and store the response in a table |
| queryServices (self, service, host, port, mcast) |
Performs a DNS-SD query against a host |
| serviceCompare (a, b) |
Function used to compare discovered DNS services so they can be sorted |
| setMulticast (self, mcast) |
Instructs the helper to use unconnected sockets supporting multicast |
| threadCount (threads) |
Returns the amount of currenlty active threads |
Functions
- createSvcHostTbl (response)
-
Creates a service host table
['_ftp._tcp.local'] = {10.10.10.10,20.20.20.20} ['_http._tcp.local'] = {30.30.30.30,40.40.40.40}
Parameters
-
response:
containing multiple responses from
dns.query
Return value:
services table containing the service name as a key and all host addresses as value -
response:
containing multiple responses from
- decodeRecords (response, result)
-
Decodes a record received from the
queryServicefunctionParameters
-
response:
as returned by
queryService - result: table into which the decoded output should be stored
-
response:
as returned by
- getRecordType (dtype, response, retAll)
-
Gets a record from both the Answer and Additional section
Parameters
- dtype: DNS resource record type.
- response: Decoded DNS response.
- retAll: If true, return all entries, not just the first.
Return values:
- True if one or more answers of the required type were found - otherwise false.
- Answer according to the answer fetcher for
dtypeor an Error message.
- getUniqueServices (response)
-
Creates a unique list of services
Parameters
-
response:
containing a single or multiple responses from
dns.query
Return value:
array of strings containing service names -
response:
containing a single or multiple responses from
- ipCompare (a, b)
-
Compare function used for sorting IP-addresses
Parameters
- a: table containing first item
- b: table containing second item
Return value:
true if a is less than b - new (self, host, port)
-
Creates a new helper instance
Parameters
- self:
- host: string containing the host name or ip
- port: number containing the port to connect to
Return value:
o a new instance of Helper - queryAllServices (host, port, multiple)
-
Query the mDNS resolvers for a list of their services
Parameters
- host: table as received by the action function
- port: number specifying the port to connect to
- multiple: receive multiple responses (multicast)
Return values:
- True if a dns response was received and contained an answer of the requested type, or the decoded dns response was requested (retPkt) and is being returned - or False otherwise.
- String answer of the requested type, Table of answers or a String error message of one of the following: "No Such Name", "No Servers", "No Answers", "Unable to handle response"
- queryService (host, port, svc, multiple, svcresponse)
-
Send a query for a particular service and store the response in a table
Parameters
- host: string containing the ip to connect to
- port: number containing the port to connect to
- svc: the service record to retrieve
- multiple: true if responses from multiple hosts are expected
- svcresponse: table to which results are stored
- queryServices (self, service, host, port, mcast)
-
Performs a DNS-SD query against a host
Parameters
- self:
- service: string or table with the service(s) to query eg. _ssh._tcp.local, _afpovertcp._tcp.local if nil defaults to _services._dns-sd._udp.local (all)
- host: table as received by the action function
- port: number specifying the port to connect to
- mcast: boolean true if a multicast query is to be done
Return values:
- status true on success, false on failure
- response table suitable for
stdnse.format_output
- serviceCompare (a, b)
-
Function used to compare discovered DNS services so they can be sorted
Parameters
- a: table containing first item
- b: table containing second item
Return value:
true if the port of a is less than the port of b - setMulticast (self, mcast)
-
Instructs the helper to use unconnected sockets supporting multicast
Parameters
- self:
- mcast: boolean true if multicast is to be used, false otherwise
- threadCount (threads)
-
Returns the amount of currenlty active threads
Parameters
- threads: table containing the list of threads
Return value:
count number containing the number of non-dead threads


