0

I'd like to make a parser for DNS records (e.g. what gets returned by dig), but I can't find a standard textual representation - as far as I can tell the RFCs just specify the wire format. However, the intro in https://tools.ietf.org/id/draft-daley-dnsxml-00.html implies that there is a standard format:

Historically, DNS Resource Records (RRs) have a presentation format and wire format. The presentation format is typically used to conveniently store DNS RRs in Human Readable Form.

Does anyone know if these presentation formats are defined anywhere?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user693861
  • 339
  • 3
  • 15

1 Answers1

0

The "zone file" format is standardized is standardized in section 5 of RFC1035

This is the standard text representation.

But about

I'd like to make a parser for DNS records (e.g. what gets returned by dig)

Do not make a parser on dig output. Use any kind of programming language you want, you will find libraries doing DNS requests and then use those to get results in proper structures, instead of trying to parse textual output from a command. You will then also be free of any actual textual representation of records.

Community
  • 1
  • 1
Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54
  • Thanks, but the idea was to create something to help someone understand the fields in a DNS record as returned by e.g. `dig`. Kind of like what https://explainshell.com/ does for shell commands. So I'm not planning on doing any DNS queries myself. – user693861 Oct 12 '18 at 15:59
  • @user693861 I still think parsing `dig` text output for anything not trivial/oneshot is not a good idea. You will hit various problems with whitespaces, return of lines, timeouts, broken servers, etc. You do not need to do DNS queries yourselves, you can let a library do it for you. For example in Python see this example: https://stackoverflow.com/questions/13842116/how-do-we-get-txt-cname-and-soa-records-from-dnspython#14178752. The library does the DNS stuff and gives back to you structured data you can analyze and use in any way you wish. – Patrick Mevzek Oct 12 '18 at 16:47
  • Right I understand that, it's just not my use case. I want someone else who has already done a DNS query to be able to use my service to interpret the results. The point of my question was to see if there was a standard format for the textual representation, but based on your answer it appears that there is not. – user693861 Oct 12 '18 at 17:07
  • " if there was a standard format for the textual representation", again, there is, the zonefile master format defined in section 5 of RFC1035. It is mostly of relevance for the authoritative nameservers that feed themselves all of this. DNS is a binary format, the DNS client gets data in a wire format and then parses it. It happens that `dig` displays it in the zone master format because it is a **troubleshooting** tool for **humans** so better to have "nice" looking output. This output is not expected to be used by other programs... – Patrick Mevzek Oct 12 '18 at 17:09
  • "someone else who has already done a DNS query" how can you be sure it did it with `dig` (a lot of people still uses `nslookup` or even `host`) ? And the proper options that make sense for the case in hand? Many `dig` options will change what is displayed and how it is displayed. You can always parse stuff I am just saying you will have a lot of cases to cater about and a lot of surprises... – Patrick Mevzek Oct 12 '18 at 17:11
  • I assumed that **if** there was a standard text format that would eliminate the variations in how different tools displayed the records, so my question really was whether or not such a standard format existed. It sounds like the answer is no, so this won't be possible. Thanks for the help. – user693861 Oct 12 '18 at 17:33
  • See the `+multi` keyword for example in dig, and how it changes the result display. Both variants are legal per the format, you would just need to cater for both. Among many other possible different display changes. – Patrick Mevzek Oct 12 '18 at 17:41