Making DNS Zones

dns.zone.from_text(text: str, origin: Name | str | None = None, rdclass: RdataClass = RdataClass.IN, relativize: bool = True, zone_factory: Any = <class 'dns.zone.Zone'>, filename: str | None = None, allow_include: bool = False, check_origin: bool = True, idna_codec: IDNACodec | None = None, allow_directives: bool | Iterable[str] = True) Zone[source]

Build a zone object from a zone file format string.

Parameters:
  • text (str) – The zone file format input.

  • origin (dns.name.Name, str, or None) – The origin of the zone. If not specified, the first $ORIGIN statement in the zone file will determine the origin.

  • rdclass (dns.rdataclass.RdataClass) – The zone’s rdata class; the default is class IN.

  • relativize (bool) – Whether domain names are relativized to the zone’s origin. The default is True.

  • zone_factory – The zone factory to use. If None, then dns.zone.Zone will be used. The value may be any class or callable that returns a subclass of dns.zone.Zone.

  • filename (str or None) – The filename to emit when describing where an error occurred; the default is '<string>'.

  • allow_include (bool) – If True (the default), then $INCLUDE directives are permitted. If False, then encountering a $INCLUDE will raise a SyntaxError.

  • check_origin (bool) – If True (the default), then sanity checks of the origin node will be made by calling dns.zone.Zone.check_origin().

  • idna_codec (dns.name.IDNACodec or None) – The IDNA encoder/decoder. If None, the default IDNA encoder/decoder is used.

  • allow_directives (bool or Iterable[str]) – If True (the default), directives are permitted and allow_include controls $INCLUDE. If False or an empty iterable, no directive processing is done. If a non-empty iterable, only the listed directives (including the $) are allowed.

Raises:
Returns:

A subclass of dns.zone.Zone.

dns.zone.from_file(f: Any, origin: Name | str | None = None, rdclass: RdataClass = RdataClass.IN, relativize: bool = True, zone_factory: Any = <class 'dns.zone.Zone'>, filename: str | None = None, allow_include: bool = True, check_origin: bool = True, idna_codec: IDNACodec | None = None, allow_directives: bool | Iterable[str] = True) Zone[source]

Read a zone file and build a zone object.

Parameters:
  • f – A file object or a str filename. If a string, it is treated as the name of a file to open.

  • origin (dns.name.Name, str, or None) – The origin of the zone. If not specified, the first $ORIGIN statement in the zone file will determine the origin.

  • rdclass (dns.rdataclass.RdataClass) – The zone’s rdata class; the default is class IN.

  • relativize (bool) – Whether domain names are relativized to the zone’s origin. The default is True.

  • zone_factory – The zone factory to use. If None, then dns.zone.Zone will be used. The value may be any class or callable that returns a subclass of dns.zone.Zone.

  • filename (str or None) – The filename to emit when describing where an error occurred; the default is '<string>'.

  • allow_include (bool) – If True (the default), then $INCLUDE directives are permitted. If False, then encountering a $INCLUDE will raise a SyntaxError.

  • check_origin (bool) – If True (the default), then sanity checks of the origin node will be made by calling dns.zone.Zone.check_origin().

  • idna_codec (dns.name.IDNACodec or None) – The IDNA encoder/decoder. If None, the default IDNA encoder/decoder is used.

  • allow_directives (bool or Iterable[str]) – If True (the default), directives are permitted and allow_include controls $INCLUDE. If False or an empty iterable, no directive processing is done. If a non-empty iterable, only the listed directives (including the $) are allowed.

Raises:
Returns:

A subclass of dns.zone.Zone.

dns.zone.from_xfr(xfr: Any, zone_factory: Any = <class 'dns.zone.Zone'>, relativize: bool = True, check_origin: bool = True) Zone[source]

Convert the output of a zone transfer generator into a zone object.

Parameters:
  • xfr – A generator of dns.message.Message objects, typically from dns.query.xfr().

  • zone_factory – The zone factory to use. If None, then dns.zone.Zone will be used.

  • relativize (bool) – Whether domain names are relativized to the zone’s origin. The default is True. It is essential that this setting matches the one specified to the generator.

  • check_origin (bool) – If True (the default), then sanity checks of the origin node will be made by calling dns.zone.Zone.check_origin().

Raises:
Returns:

A subclass of dns.zone.Zone.