zoneparser

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2024 License: LGPL-2.1 Imports: 11 Imported by: 0

README

Zone Parser

Zone Parser is a simple to use Go library that can parse bind like DNS-Zones.

Reading existing zone files

func main() {
	zoneFile, _ := ioutil.ReadFile("myzonefile")
	zone := ParseZone(string(zoneFile))
}

Writing a Zone to a file

Note that ToZoneFile will not preserve the format of zones that where parsed by ParseZone.

func main() {
	zoneFile, _ := ioutil.ReadFile("myzonefile")
	zone := ParseZone(string(zoneFile))
	zoneFile = zone.ToZoneFile() // Returns zone as string
}

Updating the serial

Zone Parser can update the serial of your zone. There are two differend methods of serial updating available. You can use Zone.UpdateSerial for updating the serial with the current UTC UNIX timestamp or Zone.UpdateSerialRFC to update your zone with the RFC compliant serial representation.

func updateSerial(z *Zone) {
		z.UpdateSerial() // z.SOA.Serial -> UNIX timestamp
		z.UpdateSerialRFC() // z.SOA.Serial -> RFC compliant representation (yyyymmdd00)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ParseState

type ParseState struct {
	Parenthesis  bool
	Quote        bool
	PreviousName string
}

ParseState represents the current state of the zone parser. ParseState is used by parseZone and does not need to be used manually.

type Record

type Record struct {
	Class   string
	Content string
	Host    string
	Ttl     uint
	Type    string
}

Record represents a single DNS resource record

type Zone

type Zone struct {
	SOA     *ZoneSOA
	Origin  string
	Records []Record
	Ttl     uint
}

Zone represents a DNS zone. It can either be instantiated manually or by using ToZoneFile

func ParseZone

func ParseZone(bindZone string) (*Zone, error)

ParseZone parses a bind-like zone file and returns a Zone struct.

func (*Zone) AddPTR

func (z *Zone) AddPTR(IP string, Host string, Ttl uint) error

AddPTR adds a creates a PTR from an IP address and adds it to the zone. If Ttl is 0 the default TTl from the zone is being used. Note: Legacy IP is currently not supported.

func (*Zone) ToZoneFile

func (z *Zone) ToZoneFile() (string, error)

ToZoneFile returns a string containing a bind-like zone file from the provided zone

func (*Zone) UpdateSerial