dns(3tcl)
π¦ 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 thetcludppackage installed, and you need a version that correctly handles binary data (> 1.0.4). it's available athttp://tcludp.sourceforge.net/. if theudppackage 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. π
-nameserverhostname,-serverhostname β specify an alternative name server for this request.-protocoltcp|udp β specify the network protocol to use for this request. can be one oftcporudp.-portportnum β specify an alternative port.-searchdomainlist-timeoutmilliseconds β override the default timeout.-typeTYPE β specify the type of DNS record you're interested in. valid values areA,NS,MD,MF,CNAME,SOA,MB,MG,MR,NULL,WKS,PTR,HINFO,MINFO,MX,TXT,SPF,SRV,AAAA,AXFR,MAILB,MAILAand*. see RFC1035 for details about the return values. seehttp://spf.pobox.com/about SPF. see (3) aboutAAAArecords and RFC2782 for details ofSRVrecords.-classCLASS β specify the class of domain name. this is usuallyINbut may be one ofINfor internet domain names,CS,CH,HSor*for any class.-recurseboolean β set tofalseif you do not want the name server to recursively act upon your request. normally set totrue.-commandprocname β set a procedure to be called upon request completion. the procedure will be passed the token as its only argument.-usetlsboolean β set totrueto use DNS over TLS. this will force the use of TCP and change the default port to853. certificate validation is required so a source of trusted certificate authority certificates must be provided using-cafileor-cadir.-cafilefilepath β specify a file containing a collection of trusted certificate authority certficates. see theupdate-ca-certificatescommand manual page for details or the-CAfileoption help fromopenssl.-cadirdirpath β specify a directory containing trusted certificate authority certificates. this must be provided if-cafileis not specified for certificate validation to work when-usetlsis enabled. see theopenssldocumentation 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.
-nameserverhostname β set the default name server to be used by all queries. the default islocalhost.-protocoltcp|udp β set the default network protocol to be used. default istcp.-portportnum β set the default port to use on the name server. the default is53.-searchdomainlist β set the domain search list. this is currently not used.-timeoutmilliseconds β set the default timeout value for DNS lookups. default is 30 seconds.-loglevellevel β set the log level used for emitting diagnostic messages from this package. the default iswarn. see thelogpackage for details of the available levels.-cafilefilepath β set the default file path to be used for the-cafileoption todns::resolve.-cadirdirpath β set the default directory path to be used for the-cadiroption todns::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 π
- Mockapetris, P., "Domain Names - Concepts and Facilities", RFC 1034, November 1987. (
http://www.ietf.org/rfc/rfc1034.txt) - Mockapetris, P., "Domain Names - Implementation and Specification", RFC 1035, November 1087. (
http://www.ietf.org/rfc/rfc1035.txt) - Thompson, S. and Huitema, C., "DNS Extensions to support IP version 6", RFC 1886, December 1995. (
http://www.ietf.org/rfc/rfc1886.txt) - Josefsson, S., "Domain Name System Uniform Resource Identifiers", Internet-Draft, October 2003, (
http://www.ietf.org/internet-drafts/draft-josefsson-dns-url-09.txt) - 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) - Ohta, M. "Incremental Zone Transfer in DNS", RFC 1995, August 1996, (
http://www.ietf.org/rfc/rfc1995.txt) - 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 π
β KEYWORDS β
DNS, domain name service, resolver, rfc 1034, rfc 1035, rfc 1886, rfc 7858
πΈ CATEGORY πΈ
Networking
π COPYRIGHT π
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
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2002, Pat Thoyts
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms