DNSLib

A library for various DNS operations

Important

To use this library, a functioning DNS Server is required.

Contents:

Dependencies

Properties

Name

Type

Default

dnsAddress

string

""

dnsAddress

The address of the DNS Server.

dnslib.dnsAddress = ""
  • Type: string

  • Default: ""

Note

This property is set using init()


Functions

init()

Initializes DNSLib and sets dnsAddress to an address read from the /.dnsAddress file. If the file does not exist the function will return -1.

function dnslib.init()
    ...
    return success
end

Arguments: nil

Returns:

Type

Description

boolean

Initialization success.

Warning

This function returns -1 instead of the above, if one of these conditions is met:

  • /.dnsAddress file does not exist.

  • Address read from /.dnsAddress is empty or nil.

Example:

local dnslib = require("dnslib")
dnslib.init()

This would initialize DNSLib and set dnsAddress to an addres found in /.dnsAddress.


lookup()

Looks up the specified domain and returns the address of the registered server.

function dnslib.lookup(domain)
    ...
    return address
end

Arguments:

Name

Type

Default

Description

domain

string

nil

Domain to look up.

Returns:

Type

Description

string

Address of the corresponding registered server.

Warning

This function returns -1 instead of the above, if one of these conditions is met:

Example:

local dnslib = require("dnslib")
local address = dnslib.lookup("test.com")

Here address would contain the address the DNS Server knows for "test.com"


lookupMultiple()

Looks up the multiple domains and returns the addresses of the registered servers.

Note

This function calls lookup() for each domain.

function dnslib.lookupMultiple(domains)
    ...
    return addresses
end

Arguments:

Name

Type

Default

Description

domains

table

nil

Domains to look up.

Returns:

Type

Description

table

Addresses of the corresponding registered servers.

Warning

This function returns -1 instead of the above, if one of these conditions is met:

  • Any lookup operation failed (lookup() returned -1).

Example:

local dnslib = require("dnslib")
local domains = {
    "test1.com",
    "test2.com"
}

local addresses = dnslib.lookupMultiple(domains)

Here addresses would contain the addresses of both, test1.com and test2.com. If either one of those would cause an error in lookup(), addresses would contain -1.