dns(3tcl)

πŸ“¦
version 2.0 Β· 3 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ¦‹ dns β€” Tcl Domain Name Service Client πŸ¦‹

okay so bestie, this is the dns(3tcl) page β€” it lives in the Domain Name Service corner of the manual, it's from tcllib, and it's literally your girl's guide to doing DNS from inside Tcl. no cap. πŸ’…


✨ SYNOPSIS ✨

package require Tcl 8.5 9

package require dns ?1.6.1?

::dns::resolve query ?options?

::dns::configure ?options?

::dns::name token

::dns::address token

::dns::cname token

::dns::result token

::dns::status token

::dns::error token

::dns::reset token

::dns::wait token

::dns::cleanup token

::dns::nameservers

🌸 DESCRIPTION 🌸

so the dns package gives you a Tcl only Domain Name Service client. that's the whole vibe. if you wanna actually understand the DNS protocol you should go read (1) and (2), or peek at resolver(3) to see how the C library does domain name resolution. 🫢

the intention here is to insulate your Tcl scripts from all the mess that comes with using the system library resolver when the name servers are slow. does it work in practice? it may or may not be of practical use. iconic honesty, honestly. 😭

internet name resolution is a complex business and DNS is only one part of the resolver. sometimes the universe has decided you're supposed to be using hosts files, NIS or WINS, just to name a few other systems. this package is not a substitute for the C library resolver β€” it does, however, implement name resolution over DNS. no notes. ✨

the package also extends the uri package so you can use DNS URIs (4) shaped like dns:what.host.com or dns://my.nameserver/what.host.com. and dns::resolve can take either a DNS URI or a plain old domain name as its query. slay. πŸ’–

Note: the package defaults to using DNS over TCP connections. if you wanna use UDP you'll need the tcludp package installed, and you need a version that correctly handles binary data (> 1.0.4). it's available at http://tcludp.sourceforge.net/. if the udp package is present, then UDP gets used by default. πŸ¦‹
Note: the package supports DNS over TLS (RFC 7858) for enhanced privacy of DNS queries. using this feature requires the TLS package. πŸ”₯

πŸ‘‘ COMMANDS πŸ‘‘

::dns::resolve query ?options?

resolve a domain name using the DNS protocol. query is the domain name to be looked up. this should be either a fully qualified domain name or a DNS URI. periodt. πŸ’…

  • -nameserver hostname, -server hostname β€” specify an alternative name server for this request.
  • -protocol tcp|udp β€” specify the network protocol to use for this request. can be one of tcp or udp.
  • -port portnum β€” specify an alternative port.
  • -search domainlist
  • -timeout milliseconds β€” override the default timeout.
  • -type TYPE β€” specify the type of DNS record you're interested in. valid values are A, NS, MD, MF, CNAME, SOA, MB, MG, MR, NULL, WKS, PTR, HINFO, MINFO, MX, TXT, SPF, SRV, AAAA, AXFR, MAILB, MAILA and *. see RFC1035 for details about the return values. see http://spf.pobox.com/ about SPF. see (3) about AAAA records and RFC2782 for details of SRV records.
  • -class CLASS β€” specify the class of domain name. this is usually IN but may be one of IN for internet domain names, CS, CH, HS or * for any class.
  • -recurse boolean β€” set to false if you do not want the name server to recursively act upon your request. normally set to true.
  • -command procname β€” set a procedure to be called upon request completion. the procedure will be passed the token as its only argument.
  • -usetls boolean β€” set to true to use DNS over TLS. this will force the use of TCP and change the default port to 853. certificate validation is required so a source of trusted certificate authority certificates must be provided using -cafile or -cadir.
  • -cafile filepath β€” specify a file containing a collection of trusted certificate authority certficates. see the update-ca-certificates command manual page for details or the -CAfile option help from openssl.
  • -cadir dirpath β€” specify a directory containing trusted certificate authority certificates. this must be provided if -cafile is not specified for certificate validation to work when -usetls is enabled. see the openssl documentation for the required structure of this directory.

::dns::configure ?options?

the ::dns::configure command is used to setup the dns package. the server to query, the protocol and the domain search path are all set through this command. πŸŽ€

if no arguments are provided then a list of all the current settings is returned. if there's only one argument then it must be the name of an option and the value for that option is returned.

  • -nameserver hostname β€” set the default name server to be used by all queries. the default is localhost.
  • -protocol tcp|udp β€” set the default network protocol to be used. default is tcp.
  • -port portnum β€” set the default port to use on the name server. the default is 53.
  • -search domainlist β€” set the domain search list. this is currently not used.
  • -timeout milliseconds β€” set the default timeout value for DNS lookups. default is 30 seconds.
  • -loglevel level β€” set the log level used for emitting diagnostic messages from this package. the default is warn. see the log package for details of the available levels.
  • -cafile filepath β€” set the default file path to be used for the -cafile option to dns::resolve.
  • -cadir dirpath β€” set the default directory path to be used for the -cadir option to dns::resolve.

::dns::name token

returns a list of all domain names returned as an answer to your query. πŸ“

::dns::address token

returns a list of the address records that match your query.

::dns::cname token

returns a list of canonical names (usually just one) matching your query.

::dns::result token

returns a list of all the decoded answer records provided for your query. this lets you extract the result for more unusual query types. iykyk. 🧚

::dns::status token

returns the status flag. for a successfully completed query this will be ok. may be error or timeout or eof. see also ::dns::error.

::dns::error token

returns the error message provided for requests whose status is error. if there is no error message then an empty string is returned.

::dns::reset token

reset or cancel a DNS query. bye bestie πŸ‘‹

::dns::wait token

wait for a DNS query to complete and return the status upon completion.

::dns::cleanup token

remove all state variables associated with the request. so tidy ✨

::dns::nameservers

attempts to return a list of the nameservers currently configured for the user's system. on a unix machine this parses the /etc/resolv.conf file for nameservers (if it exists) and on Windows systems we examine certain parts of the registry. if no nameserver can be found then the loopback address (127.0.0.1) is used as a default. 🫢


🌈 EXAMPLES 🌈

% set tok [dns::resolve www.tcl.tk]
::dns::1
% dns::status $tok
ok
% dns::address $tok
199.175.6.239
% dns::name $tok
www.tcl.tk
% dns::cleanup $tok

using DNS URIs as queries:

% set tok [dns::resolve "dns:tcl.tk;type=MX"]
% set tok [dns::resolve "dns://l.root-servers.net/www.tcl.tk"]

reverse address lookup:

% set tok [dns::resolve 127.0.0.1]
::dns::1
% dns::name $tok
localhost
% dns::cleanup $tok

using DNS over TLS (RFC 7858):

% set tok [dns::resolve www.tcl.tk -nameserver dns-tls.bitwiseshift.net  -usetls 1 -cafile /etc/ssl/certs/ca-certificates.crt]
::dns::12
% dns::wait $tok
ok
% dns::address $tok
104.25.119.118 104.25.120.118

πŸ’œ REFERENCES πŸ’œ

  1. Mockapetris, P., "Domain Names - Concepts and Facilities", RFC 1034, November 1987. (http://www.ietf.org/rfc/rfc1034.txt)
  2. Mockapetris, P., "Domain Names - Implementation and Specification", RFC 1035, November 1087. (http://www.ietf.org/rfc/rfc1035.txt)
  3. Thompson, S. and Huitema, C., "DNS Extensions to support IP version 6", RFC 1886, December 1995. (http://www.ietf.org/rfc/rfc1886.txt)
  4. Josefsson, S., "Domain Name System Uniform Resource Identifiers", Internet-Draft, October 2003, (http://www.ietf.org/internet-drafts/draft-josefsson-dns-url-09.txt)
  5. Gulbrandsen, A., Vixie, P. and Esibov, L., "A DNS RR for specifying the location of services (DNS SRV)", RFC 2782, February 2000, (http://www.ietf.org/rfc/rfc2782.txt)
  6. Ohta, M. "Incremental Zone Transfer in DNS", RFC 1995, August 1996, (http://www.ietf.org/rfc/rfc1995.txt)
  7. Hu, Z., etc al. "Specification for DNS over Transport Layer Security (TLS)", RFC 7858, May 2016, (http://www.ietf.org/rfc/rfc7858.txt)
(yes, reference 2 says November 1087 in the original. i am not touching it. that's history now πŸ’€)

πŸŽ€ AUTHORS πŸŽ€

Pat Thoyts


😭 BUGS, IDEAS, FEEDBACK 😭

this document, and the package it describes, will undoubtedly contain bugs and other problems. not even being dramatic, it just says that. please report such in the category dns of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. please also report any ideas for enhancements you may have for either the package and/or the documentation. we love ideas here. 🫢

when proposing code changes, please provide unified diffs, i.e. the output of diff -u.

note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. iconic workflow, love that for you. ✨


πŸ‘€ SEE ALSO πŸ‘€

resolver(5)


⭐ KEYWORDS ⭐

DNS, domain name service, resolver, rfc 1034, rfc 1035, rfc 1886, rfc 7858


🌸 CATEGORY 🌸

Networking


Copyright (c) 2002, Pat Thoyts


and that's the whole page bestie πŸ₯° this one came out of tcllib 1.6.1, the manual page is dns(3tcl), and that's genuinely it β€” go resolve some names, you're gonna eat πŸ’…πŸŒΈβœ¨

πŸ“¦ where this page comes from