Skip to content

Instantly share code, notes, and snippets.

@hlandau
Last active January 24, 2016 18:22
Show Gist options
  • Save hlandau/93a45884db97e8dcaeba to your computer and use it in GitHub Desktop.
Save hlandau/93a45884db97e8dcaeba to your computer and use it in GitHub Desktop.
Convert any DNS record to generic RFC3597 syntax
// Reads DNS records in zone file format on stdin and outputs them in generic
// RFC3597 format. This is useful if you need to configure DNS records for a
// nameserver which doesn't support the rrtypes you're trying to configure.
//
// Supports whatever rrtypes that github.com/miekg/dns supports, which tends to
// be pretty exhaustive.
package main
import (
"fmt"
"github.com/hlandau/xlog"
"github.com/miekg/dns"
"os"
)
var log, Log = xlog.New("to3597")
func main() {
tokCh := dns.ParseZone(os.Stdin, ".", "stdin")
for tok := range tokCh {
if tok.Error != nil {
log.Fatale(tok.Error, "parse error")
}
if tok.RR == nil {
continue
}
genRR := dns.RFC3597{}
err := genRR.ToRFC3597(tok.RR)
if err != nil {
log.Errore(err, "convert to RFC3597")
}
fmt.Printf("%s\n", genRR.String())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment