File | Date | Author | Commit |
---|---|---|---|
.hgignore | 2025-02-06 |
![]() |
[525b21] add a .hgignore |
Makefile | 2025-02-06 |
![]() |
[262ea2] Initial commit of dns tester |
README.md | 2025-02-07 |
![]() |
[f82843] Some additional details for the README |
dnsq.lpi | 2025-02-06 |
![]() |
[262ea2] Initial commit of dns tester |
dnsq.pp | 2025-02-06 |
![]() |
[262ea2] Initial commit of dns tester |
This program was written to test the new DNS query functions I wrote for the FPC compiler project back in 2020/2021. It was intended to be included in the examples directory for netdb.pas but it never made it. I'm therefore publishing it here.
Despite being a short program containing just a few hundred lines of Pascal, including comments and debug functions, it is a fully functional DNS client with error handling and support for both UDP and TCP queries.
dnsq is a small program that functions like nslookup or dig. It takes a query type and a domain name, and it performs a DNS lookup using the local resolver and returns the resulting records. In addition to direct answers, additional section answers are also shown.
dnsq always queries using UDP first. If the response from the DNS server is truncated, dnsq will retry the query using TCP. This is the approach recommended by the RFCs.
dnsq can query any of the following DNS record types.
$ ./dnsq a google.com
- www.google.com (A)
Answers: 1 NS: 0 Additional: 0 Length: 36 AnsStart: 20
-- Answers
www.google.com 34 A 142.250.76.100
./dnsq mx x.com
- x.com (MX)
Answers: 5 NS: 0 Additional: 8 Length: 290 AnsStart: 11
-- Answers
x.com 300 MX 10 alt3.aspmx.l.google.com
x.com 300 MX 10 alt4.aspmx.l.google.com
x.com 300 MX 5 alt1.aspmx.l.google.com
x.com 300 MX 5 alt2.aspmx.l.google.com
x.com 300 MX 1 aspmx.l.google.com
-- Additional Section
aspmx.l.google.com 219 A 74.125.68.27
aspmx.l.google.com 70 AAAA 2404:6800:4003:0C02::001A
alt3.aspmx.l.google.com 219 A 142.251.186.27
alt4.aspmx.l.google.com 219 A 108.177.104.27
alt1.aspmx.l.google.com 276 A 108.177.98.27
alt1.aspmx.l.google.com 70 AAAA 2607:F8B0:400E:0C06::001B
alt2.aspmx.l.google.com 276 A 142.250.141.26
alt2.aspmx.l.google.com 70 AAAA 2607:F8B0:4023:0C0B::001
% ./dnsq txt freepascal.org
- freepascal.org (TXT)
Answers: 1 NS: 0 Additional: 0 Length: 112 AnsStart: 20
-- Answers
freepascal.org 604800 TXT v=spf1 mx a:lists.freepascal.org a:mail.freepascal.org a:fpclists.coderetro.net
A Makefile is included. The default target builds the release version of dnsq. There is a debug target to build a version with debugging information.
Release builds are written to a subdirectory named obj. Debug builds go in objdbg.
A minimum version of FPC 3.3.1 is required. That is to my knowledge the earliest release that includes the new API. If you have a new enough compiler but it's not the default on your system, you can specify a different version to the Makefile like so:
$ make FPC=~/fpc3.3.1/bin/fpc