This hardly seems like something you'd need to write yourself; I'll bet there are programs out there that can already do this.

If you do want to write your own name server, though, start with RFCs...