Package dns :: Module message
[hide private]
[frames] | no frames]

Module message

source code

DNS Messages

Classes [hide private]
  ShortHeader
The DNS packet passed to from_wire() is too short.
  TrailingJunk
The DNS packet passed to from_wire() has extra junk at the end of it.
  UnknownHeaderField
The header field name was not recognized when converting from text into a message.
  BadEDNS
OPT record occurred somewhere other than the start of the additional data section.
  BadTSIG
A TSIG record occurred somewhere other than the end of the additional data section.
  UnknownTSIGKey
A TSIG with an unknown key was received.
  Message
A DNS message.
  _WireReader
Wire format reader.
  _TextReader
Text format reader.
Functions [hide private]
dns.message.Message object
from_wire(wire, keyring=None, request_mac='', xfr=False, origin=None, tsig_ctx=None, multi=False, first=True, question_only=False, one_rr_per_rrset=False, ignore_trailing=False)
Convert a DNS wire format message into a message object.
source code
dns.message.Message object
from_text(text)
Convert the text format message into a message object.
source code
dns.message.Message object
from_file(f)
Read the next text format message from the specified file.
source code
dns.message.Message object
make_query(qname, rdtype, rdclass=1, use_edns=None, want_dnssec=False, ednsflags=None, payload=None, request_payload=None, options=None)
Make a query message.
source code
dns.message.Message object
make_response(query, recursion_available=False, our_payload=8192, fudge=300)
Make a message which is a response for the specified query.
source code
Variables [hide private]
  __package__ = 'dns'
Function Details [hide private]

from_wire(wire, keyring=None, request_mac='', xfr=False, origin=None, tsig_ctx=None, multi=False, first=True, question_only=False, one_rr_per_rrset=False, ignore_trailing=False)

source code 

Convert a DNS wire format message into a message object.

Parameters:
  • keyring (dict) - The keyring to use if the message is signed.
  • request_mac (string) - If the message is a response to a TSIG-signed request, request_mac should be set to the MAC of that request.
  • xfr (bool) - Is this message part of a zone transfer?
  • origin (dns.name.Name object) - If the message is part of a zone transfer, origin should be the origin name of the zone.
  • tsig_ctx (hmac.HMAC object) - The ongoing TSIG context, used when validating zone transfers.
  • multi (bool) - Is this message part of a multiple message sequence?
  • first (bool) - Is this message standalone, or the first of a multi message sequence?
  • question_only (bool) - Read only up to the end of the question section?
  • one_rr_per_rrset (bool) - Put each RR into its own RRset
  • ignore_trailing (bool) - Ignore trailing junk at end of request?
Returns: dns.message.Message object
Raises:
  • ShortHeader - The message is less than 12 octets long.
  • TrailingJunk - There were octets in the message past the end of the proper DNS message.
  • BadEDNS - An OPT record was in the wrong section, or occurred more than once.
  • BadTSIG - A TSIG record was not the last record of the additional data section.

from_text(text)

source code 

Convert the text format message into a message object.

Parameters:
  • text (string) - The text format message.
Returns: dns.message.Message object
Raises:

from_file(f)

source code 

Read the next text format message from the specified file.

Parameters:
  • f - file or string. If f is a string, it is treated as the name of a file to open.
Returns: dns.message.Message object
Raises:

make_query(qname, rdtype, rdclass=1, use_edns=None, want_dnssec=False, ednsflags=None, payload=None, request_payload=None, options=None)

source code 

Make a query message.

The query name, type, and class may all be specified either as objects of the appropriate type, or as strings.

The query will have a randomly chosen query id, and its DNS flags will be set to dns.flags.RD.

Parameters:
  • qname (dns.name.Name object or string) - The query name.
  • rdtype (int) - The desired rdata type.
  • rdclass (int) - The desired rdata class; the default is class IN.
  • use_edns (int or bool or None) - The EDNS level to use; the default is None (no EDNS). See the description of dns.message.Message.use_edns() for the possible values for use_edns and their meanings.
  • want_dnssec (bool) - Should the query indicate that DNSSEC is desired?
  • ednsflags (int) - EDNS flag values.
  • payload (int) - The EDNS sender's payload field, which is the maximum size of UDP datagram the sender can handle.
  • request_payload (int or None) - The EDNS payload size to use when sending this message. If not specified, defaults to the value of payload.
  • options (None or list of dns.edns.Option objects) - The EDNS options
Returns: dns.message.Message object

See Also: RFC 2671

make_response(query, recursion_available=False, our_payload=8192, fudge=300)

source code 

Make a message which is a response for the specified query. The message returned is really a response skeleton; it has all of the infrastructure required of a response, but none of the content.

The response's question section is a shallow copy of the query's question section, so the query's question RRsets should not be changed.

Parameters:
  • query (dns.message.Message object) - the query to respond to
  • recursion_available (bool) - should RA be set in the response?
  • our_payload (int) - payload size to advertise in EDNS responses; default is 8192.
  • fudge (int) - TSIG time fudge; default is 300 seconds.
Returns: dns.message.Message object