msys.dnsLookup
Name
msys.dnsLookup — Perform a DNS lookup
Synopsis
msys.dnsLookup(name, recordtype, options);
name: string recordtype: string (optional) options: table (optional)
Description
Perform a DNS lookup. The parameters are as follows:
- 
name - 
recordtype– If not specified,recordtypedefaults toA. Otherwise, it is a string from the following list:- 
ALookup the IPv4 address - 
AAAALookup the IPv6 address - 
TXTLookup a TXT record - 
MXLookup an MX record - 
PTRLookup a PTR record - 
NSLookup an NS record 
Warning
If
recordtypeis passed an invalid value, then an exception is thrown. In this case, the inbound session will return a 421 error. - 
 - 
options– Table with the following keys:- 
priority– Either true or false. If unspecified, false is assumed. - 
server– Optional alternate DNS server to query instead of the system default resolver 
 - 
 
Because this function is in the msys namespace, an explicit require('msys') is not necessary.
This function returns the following:
- 
On success, the return value is a table containing the results.
For records with a preference value, if
priorityis set totrue, the values returned are themselves tables with the first element being the preference value and the second element the string value. Otherwise, the values returned are just the string values. Regardless of the value of theprioritysetting, the returned records are ordered based on their preference, with the "best" record first. For other records, the values are simply string values that are ordered as they appear in the DNS response. - 
For a failed lookup, two values are returned:
- 
nilto indicate error - 
errmsgthe error message 
 - 
 
The idiom for performing a DNS lookup is:
local results, errmsg, result; results, errmsg = msys.dnsLookup('messagesystems.com', 'A'); if results == nil then print("ERROR: " .. errmsg); return; end if results ~= nil then for k,v in ipairs(results) do print("key: " .. k .. "and value: " .. v) end end
Note
Results of msys.dnsLookup() invocations in your policy scripts can also be queried from the system console by using dns_cache stats.