Writing a client to query DNS

Matthew Thompson matthewt at fairplay.co.uk
Fri Feb 25 14:08:43 UTC 2000


Not sure if this is necessarily the best place for this query but
comp.protocols.dns is empty...

I'm trying - with limited success - to write a client to query a DNS
server for specific information.

I have succeeded in getting a response from the DNS server but it
reports in the RCODE a 2 (Server failiure).

Since this is our company's main DNS server and other query tools work
I'm tempted to believe that it might be a problem with my software.

I'm writing it in VB6 as it is to end up as a component in an existing
vb6 application.

Source code follows at the end of this message - as you'll see it's
very very basic and fully commented.

Querying our DNS server 213.38.23.131 using a query string of
www.fairplay.co.uk (Our Web server 213.38.23.135) creates the request:

ID: 10000001001001 (64, 73)
QR: 0 (0)
Opcode: 0000 (0)
AA: 0 (0)
TC: 0 (0)
RD: 1 (1)
RA: 0 (0)
Z: 000 (0)
RCODE 0000 (0)
QDCOUNT: 0000000000000001 (1)
ANCOUNT: 0000000000000000 (0)
NSCOUNT: 0000000000000000 (0)
ARCOUNT: 0000000000000000 (0)
QNAME LengthOctet: 00010010 (18)
QNAME Data: www.fairplay.co.uk
QNAME NullOctet: 00000000 (0)
QTYPE: 100000100000000 (A)
QCLASS: 10010011001110 (IN)

to which I get the following response

ID: 10000001001001 (64, 73)
QR: 1 (1)
Opcode: 0000 (0)
AA: 0 (0)
TC: 0 (0)
RD: 1 (1)
RA: 1 (1)
Z: 000 (0)
RCODE 0010 (2)
QDCOUNT: 0000000000000001 (1)
ANCOUNT: 0000000000000000 (0)
NSCOUNT: 0000000000000000 (0)
ARCOUNT: 0000000000000000 (0)
QNAME LengthOctet: 00010010 (18)
QNAME Data: www.fairplay.co.uk
QNAME NullOctet: 00000000 (0)
QTYPE: 100000100000000 (A)
QCLASS: 10010011001110 (IN)

Any help would be greatly appreciated.

Source code next.

M at t :o)

Option Explicit

Private Sub Command1_Click()
    Dim txtHost As String
    Dim datatosend As String
    Dim QueryString As String
    '- Set the DNS server to query
    txtHost = "dns"
    '- Set QueryString to be the machine/network to search for -
entered on form/
    QueryString = Me.txtQueryString
    '- Set protocol to UDP
    Winsock1.Protocol = sckUDPProtocol
    '- Connect to Host, port 53
    Winsock1.Connect Trim(txtHost), 53
    '- Create string to send
    '- Set request ID
    datatosend = Chr(64) & Chr(73)
    '- Set QR, Opcode, AA, TC, RD, RA, Z, RCODE (0000000100000000)
    datatosend = datatosend & Chr(1) & Chr(0)
    '- Set QDCOUNT (0000000000000001)
    datatosend = datatosend & Chr(0) & Chr(1)
    '- Set ANCOUNT (0000000000000000)
    datatosend = datatosend & Chr(0) & Chr(0)
    '- Set NSCOUNT (0000000000000000)
    datatosend = datatosend & Chr(0) & Chr(0)
    '- Set ARCOUNT (0000000000000000)
    datatosend = datatosend & Chr(0) & Chr(0)
    '- Set Length Octet
    datatosend = datatosend & Chr(Len(QueryString))
    '- Set QNAME
    datatosend = datatosend & Trim(QueryString)
    '- Set QNAME terminator (null)
    datatosend = datatosend & Chr(0)
    '- Set QTYPE
    datatosend = datatosend & "A" & chr(0)
    '- Set QCLASS
    datatosend = datatosend & "IN"
    '- Send data
    Winsock1.SendData datatosend
    '- Event loop to allow for reception of data
    Do
        DoEvents
    Loop
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim strServerResponse   As String
    Dim strResponseCode     As String
    Dim t As Integer
    '- Get Data
    Winsock1.GetData strServerResponse
    '- Print data as string
    Debug.Print "BACK " & strServerResponse
    '- Loop through octets and print decimal value
    For t = 1 To Len(strServerResponse)
        Debug.Print Format(t, "0000") & " " &
Asc(Mid(strServerResponse, t, 1))
    Next t
End Sub


-- 
Matthew Thompson - Fairplay Publications
e: matthewt at fairplay.co.uk
t: +44 20 8645 2800
f: +44 20 8660 2824 



More information about the bind-users mailing list