User Tools

Site Tools


querying_20the_20dns

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)
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
querying_20the_20dns.txt · Last modified: 2024/01/05 00:21 by 127.0.0.1