A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/openresty/lua-resty-dns below:

openresty/lua-resty-dns: DNS resolver for the nginx lua module

lua-resty-dns - Lua DNS resolver for the ngx_lua based on the cosocket API

This library is considered production ready.

This Lua library provides a DNS resolver for the ngx_lua nginx module:

https://github.com/openresty/lua-nginx-module/#readme

This Lua library takes advantage of ngx_lua's cosocket API, which ensures 100% nonblocking behavior.

Note that at least ngx_lua 0.5.12 or OpenResty 1.2.1.11 is required.

Also, the bit library is also required. If you're using LuaJIT 2.0 with ngx_lua, then the bit library is already available by default.

Note that, this library is bundled and enabled by default in the OpenResty bundle.

IMPORTANT: to be able to generate unique ids, the random generator must be properly seeded using math.randomseed prior to using this module.

lua_package_path "/path/to/lua-resty-dns/lib/?.lua;;";

server {
    location = /dns {
        content_by_lua_block {
            local resolver = require "resty.dns.resolver"
            local r, err = resolver:new{
                nameservers = {"8.8.8.8", {"8.8.4.4", 53} },
                retrans = 5,  -- 5 retransmissions on receive timeout
                timeout = 2000,  -- 2 sec
                no_random = true, -- always start with first nameserver
            }

            if not r then
                ngx.say("failed to instantiate the resolver: ", err)
                return
            end

            local answers, err, tries = r:query("www.google.com", nil, {})
            if not answers then
                ngx.say("failed to query the DNS server: ", err)
                ngx.say("retry historie:\n  ", table.concat(tries, "\n  "))
                return
            end

            if answers.errcode then
                ngx.say("server returned error code: ", answers.errcode,
                        ": ", answers.errstr)
            end

            for i, ans in ipairs(answers) do
                ngx.say(ans.name, " ", ans.address or ans.cname,
                        " type:", ans.type, " class:", ans.class,
                        " ttl:", ans.ttl)
            end
        }
    }
}

Back to TOC

Back to TOC

syntax: r, err = class:new(opts)

Creates a dns.resolver object. Returns nil and a message string on error.

It accepts a opts table argument. The following options are supported:

Back to TOC

syntax: r:destroy()

Destroy the dns.resolver object by releasing all the internal occupied resources.

Back to TOC

syntax: answers, err, tries? = r:query(name, options?, tries?)

Performs a DNS standard query to the nameservers specified by the new method, and returns all the answer records in an array-like Lua table. In case of errors, it will return nil and a string describing the error instead.

If the server returns a non-zero error code, the fields errcode and errstr will be set accordingly in the Lua table returned.

Each entry in the answers returned table value is also a hash-like Lua table which usually takes some of the following fields:

This method also takes an optional options argument table, which takes the following fields:

The optional parameter tries can be provided as an empty table, and will be returned as a third result. The table will be an array with the error message for each (if any) failed try.

When data truncation happens, the resolver will automatically retry using the TCP transport mode to query the current nameserver. All TCP connections are short lived.

Back to TOC

syntax: answers, err = r:tcp_query(name, options?)

Just like the query method, but enforce the TCP transport mode instead of UDP.

All TCP connections are short lived.

Here is an example:

    local resolver = require "resty.dns.resolver"

    local r, err = resolver:new{
        nameservers = { "8.8.8.8" }
    }
    if not r then
        ngx.say("failed to instantiate resolver: ", err)
        return
    end

    local ans, err = r:tcp_query("www.google.com", { qtype = r.TYPE_A })
    if not ans then
        ngx.say("failed to query: ", err)
        return
    end

    local cjson = require "cjson"
    ngx.say("records: ", cjson.encode(ans))

Back to TOC

syntax: r:set_timeout(time)

Overrides the current timeout setting by the time argument in milliseconds for all the nameserver peers.

Back to TOC

syntax: compressed = resty.dns.resolver.compress_ipv6_addr(address)

Compresses the successive 16-bit zero groups in the textual format of the IPv6 address.

For example,

    local resolver = require "resty.dns.resolver"
    local compress = resolver.compress_ipv6_addr
    local new_addr = compress("FF01:0:0:0:0:0:0:101")

will yield FF01::101 in the new_addr return value.

Back to TOC

syntax: expanded = resty.dns.resolver.expand_ipv6_addr(address)

Expands the successive 16-bit zero groups in the textual format of the IPv6 address.

For example,

    local resolver = require "resty.dns.resolver"
    local expand = resolver.expand_ipv6_addr
    local new_addr = expand("FF01::101")

will yield FF01:0:0:0:0:0:0:101 in the new_addr return value.

Back to TOC

syntax: arpa_record = resty.dns.resolver.arpa_str(address)

Generates the reverse domain name for PTR lookups for both IPv4 and IPv6 addresses. Compressed IPv6 addresses will be automatically expanded.

For example,

    local resolver = require "resty.dns.resolver"
    local ptr4 = resolver.arpa_str("1.2.3.4")
    local ptr6 = resolver.arpa_str("FF01::101")

will yield 4.3.2.1.in-addr.arpa for ptr4 and 1.0.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.F.F.ip6.arpa for ptr6.

Back to TOC

syntax: answers, err = r:reverse_query(address)

Performs a PTR lookup for both IPv4 and IPv6 addresses. This function is basically a wrapper for the query command which uses the arpa_str command to convert the IP address on the fly.

Back to TOC

Back to TOC

The A resource record type, equal to the decimal number 1.

Back to TOC

The NS resource record type, equal to the decimal number 2.

Back to TOC

The CNAME resource record type, equal to the decimal number 5.

Back to TOC

The SOA resource record type, equal to the decimal number 6.

Back to TOC

The PTR resource record type, equal to the decimal number 12.

Back to TOC

The MX resource record type, equal to the decimal number 15.

Back to TOC

The TXT resource record type, equal to the decimal number 16.

Back to TOC

syntax: typ = r.TYPE_AAAA

The AAAA resource record type, equal to the decimal number 28.

Back to TOC

syntax: typ = r.TYPE_SRV

The SRV resource record type, equal to the decimal number 33.

See RFC 2782 for details.

Back to TOC

syntax: typ = r.TYPE_SPF

The SPF resource record type, equal to the decimal number 99.

See RFC 4408 for details.

Back to TOC

syntax: class = r.CLASS_IN

The Internet resource record type, equal to the decimal number 1.

Back to TOC

syntax: stype = r.SECTION_AN

Identifier of the Answer section in the DNS response. Equal to decimal number 1.

Back to TOC

syntax: stype = r.SECTION_NS

Identifier of the Authority section in the DNS response. Equal to the decimal number 2.

Back to TOC

syntax: stype = r.SECTION_AR

Identifier of the Additional section in the DNS response. Equal to the decimal number 3.

Back to TOC

By default, the underlying ngx_lua module does error logging when socket errors happen. If you are already doing proper error handling in your own Lua code, then you are recommended to disable this automatic error logging by turning off ngx_lua's lua_socket_log_errors directive, that is,

    lua_socket_log_errors off;

Back to TOC

Back to TOC

Back to TOC

Yichun "agentzh" Zhang (章亦春) agentzh@gmail.com, OpenResty Inc.

Back to TOC

This module is licensed under the BSD license.

Copyright (C) 2012-2019, by Yichun "agentzh" Zhang (章亦春) agentzh@gmail.com, OpenResty Inc.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Back to TOC

Back to TOC


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4