I have seen what the text representation of an HTTP request is, but what does a DNS request look like? Where in the data is the location of the URL you are trying to locate? Also, how is the response formatted?
feedback
|
|
This is a raw dump from Wireshark of a DNS query. The DNS part starts with 24 1a:
And here is the breakdown:
And the repsonse, again starting at 24 1a:
Breakdown:
Edit: Note that if your real question is "how do I write a DNS server?", then there are two appropriate answers: Edit(2): The request was sent using
If you are on windows, you can use
| |||||||||
feedback
|
|
DNS request data layout is described in RFC 1035. I think it's a bit pointless to copy the text here... | |||
|
feedback
|
|
If you can get onto a Linux machine, you can run the dig command to perform a DNS lookup. This utility performs a lookup and returns exactly what the name server responds with. For example:
Everything starting with the "HEADER" section are what gets returned from the name server. I'm assuming this is what you're referring to as the text format because this isn't the format of the actual packet, but it is the text that gets returned. | |||
|
feedback
|
|
DNS queries and responses are best looked at using a protocol analyzer - Wireshark is a good cross platform tool that can capture and deconstruct the requests and responses into their various parts. There is a nice introduction to the structure of DNS Requests and Responses at Firewall.cx here. DNS Requests contain questions that specify a name (or maybe a somewhat arbitrary text field) and a record type - the content of the response will vary depending on the type. Most requests are simple direct lookups of a server name looking for an ip-address in response (Type A) but some will be looking for more information on name servers themselves (Type NS), mail records (Type MX) and other services (Type SRV that will return names, ports, weights and priorities). DNS responses contain answers to these questions, possibly more than one if the request requires that and are not always just ip-addresses. One other clarification - DNS doesn't resolve URLs - in most scenarios involving URLs DNS is only used to enable the client side system to find the ip-address of the server part of the URL, everything else is handled by other protocols. | |||
|
feedback
|