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 for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
querying_20the_20dns.txt · Last modified: 2018/04/17 18:20 by tbest3112