querying_20the_20dns
This is an old revision of the document!
Querying the DNS
by Richard Russell, October 2013
The code below allows you to query the DNS to find the IP address(es) corresponding to a specified URL:
SYS "LoadLibrary", "dnsapi.dll" TO dnsapi% SYS "GetProcAddress", dnsapi%, "DnsQuery_A" TO `DnsQuery` SYS "GetProcAddress", dnsapi%, "DnsRecordListFree" TO `DnsRecordListFree`
DIM dnsr{pNext%, pName%, wType{l&,h&}, wDataLength{l&,h&}, dwFlags%, \ \ dwTtl%, dwReserved%, dwData%}
query$ = "www.google.com"
SYS `DnsQuery`, query$, 1, 1, 0, dnsr{}, 0
rr% = dnsr.pNext%
WHILE dnsr.pNext% !(^dnsr{}+4) = dnsr.pNext% PRINT $$dnsr.pName% " ", FNipaddr$(dnsr.dwData%) ENDWHILE
SYS `DnsRecordListFree`, rr%, 0
SYS "FreeLibrary", dnsapi%
PRINT "done"
END
DEF FNipaddr$(addr%) = STR$(addr% AND 255) + "." + STR$(addr% >>> 8 AND 255) + "." + \ \ STR$(addr% >>> 16 AND 255) + "." + STR$(addr% >>> 24 AND 255)
querying_20the_20dns.1522502375.txt.gz · Last modified: 2024/01/05 00:16 (external edit)