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, orNone) – The origin of the zone. If not specified, the first$ORIGINstatement 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, thendns.zone.Zonewill be used. The value may be any class or callable that returns a subclass ofdns.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$INCLUDEdirectives are permitted. IfFalse, then encountering a$INCLUDEwill raise aSyntaxError.check_origin (bool) – If
True(the default), then sanity checks of the origin node will be made by callingdns.zone.Zone.check_origin().idna_codec (
dns.name.IDNACodecorNone) – The IDNA encoder/decoder. IfNone, 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. IfFalseor an empty iterable, no directive processing is done. If a non-empty iterable, only the listed directives (including the$) are allowed.
- Raises:
dns.zone.NoSOA – if there is no SOA RRset.
dns.zone.NoNS – if there is no NS RRset.
KeyError – if there is no origin node.
- 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
strfilename. If a string, it is treated as the name of a file to open.origin (
dns.name.Name, str, orNone) – The origin of the zone. If not specified, the first$ORIGINstatement 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, thendns.zone.Zonewill be used. The value may be any class or callable that returns a subclass ofdns.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$INCLUDEdirectives are permitted. IfFalse, then encountering a$INCLUDEwill raise aSyntaxError.check_origin (bool) – If
True(the default), then sanity checks of the origin node will be made by callingdns.zone.Zone.check_origin().idna_codec (
dns.name.IDNACodecorNone) – The IDNA encoder/decoder. IfNone, 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. IfFalseor an empty iterable, no directive processing is done. If a non-empty iterable, only the listed directives (including the$) are allowed.
- Raises:
dns.zone.NoSOA – if there is no SOA RRset.
dns.zone.NoNS – if there is no NS RRset.
KeyError – if there is no origin node.
- 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.Messageobjects, typically fromdns.query.xfr().zone_factory – The zone factory to use. If
None, thendns.zone.Zonewill 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 callingdns.zone.Zone.check_origin().
- Raises:
dns.zone.NoSOA – if there is no SOA RRset.
dns.zone.NoNS – if there is no NS RRset.
KeyError – if there is no origin node.
ValueError – if no messages are yielded by the generator.
- Returns:
A subclass of
dns.zone.Zone.