LDNS packet object.
The ldns_pkt object contains DNS packed (either a query or an answer). It is the complete representation of what you actually send to a name server, and what you get back (see ldns.ldns_resolver).
Usage
>>> import ldns
>>> resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
>>> pkt = resolver.query("nic.cz", ldns.LDNS_RR_TYPE_NS,ldns.LDNS_RR_CLASS_IN)
>>> print pkt
;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 63004
;; flags: qr rd ra ; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;; nic.cz. IN NS
;; ANSWER SECTION:
nic.cz. 758 IN NS a.ns.nic.cz.
nic.cz. 758 IN NS c.ns.nic.cz.
nic.cz. 758 IN NS e.ns.nic.cz.
;; AUTHORITY SECTION:
;; ADDITIONAL SECTION:
;; Query time: 8 msec
;; SERVER: 82.100.38.2
;; WHEN: Thu Jan 11 12:54:33 2009
;; MSG SIZE rcvd: 75
This simple example instances a resolver in order to resolve NS for nic.cz.
Read the packet’s aa bit.
Returns: | (bool) Value of the bit. |
---|
Read the packet’s ad bit.
Returns: | (bool) Value of the bit. |
---|
Return the packet’s additional section.
Returns: | (ldns_rr_list) The additional section. |
---|
Converts a signing algorithms to its mnemonic and returns that as an allocated null-terminated string.
Parameters: | alg (ldns_algorithm) – The algorithm to convert to text. |
---|---|
Returns: | (str) |
Return the packet’s question, answer, authority and additional sections concatenated.
Returns: | (ldns_rr_list) Concatenated sections. |
---|
Return the packet’s answer, authority and additional sections concatenated. Like all() but without the questions.
Returns: | (ldns_rr_list) Concatenated sections except questions. |
---|
Return the packet’s an count.
Returns: | (int) The an count. |
---|
Return the packet’s answer section.
Returns: | (ldns_rr_list) The answer section. |
---|
Return the packet’s ar count.
Returns: | (int) The ar count. |
---|
Return the packet’s authority section.
Returns: | (ldns_rr_list) The authority section. |
---|
Read the packet’s cd bit.
Returns: | (bool) Value of the bit. |
---|
Converts a cert algorithm to its mnemonic and returns that as an allocated null-terminated string.
Parameters: | alg (ldns_cert_algorithm) – Cert algorithm to convert to text. |
---|---|
Returns: | (str) |
Returns True if this packet needs and EDNS rr to be sent.
At the moment the only reason is an expected packet size larger than 512 bytes, but for instance DNSSEC would be a good reason too.
Returns: | (bool) True if packet needs EDNS rr. |
---|
Return the packet’s edns do bit
Returns: | (bool) The bit’s value. |
---|
Return the packet’s edns extended rcode.
Returns: | (uint8_t) The rcode. |
---|
Return the packet’s edns udp size.
Returns: | (uint16_t) The udp size. |
---|
Return the packet’s edns version.
Returns: | (uint8_t) The edns version. |
---|
Return the packet’s edns z value.
Returns: | (uint16_t) The z value. |
---|
Check if a packet is empty.
Returns: | (bool) True: empty, False: not empty |
---|
Read the packet’s code.
Returns: | (ldns_pkt_opcode) the opcode |
---|
Return the packet’s response code.
Returns: | (ldns_pkt_rcode) The response code. |
---|
Return the selected rr_list’s in the packet.
Parameters: | s (ldns_pkt_section) – What section(s) to return. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. | |
Returns: | (ldns_rr_list) RR list with the rr’s or None if none were found. |
Read the packet id.
Returns: | (uint16_t) The packet id. |
---|
Creates a packet with a query in it for the given name, type and class.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (ldns_pkt) New object. |
Note
The type checking of parameter rr_name is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.
Creates a query packet for the given name, type, class.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Throws Exception: | |
When raiseException set and packet couldn’t be created. |
|
Returns: | (ldns_pkt) Query packet object or None. If the object can’t be created and raiseException is True, an exception occurs. |
Usage
>>> pkt = ldns.ldns_pkt.new_query_frm_str("test.nic.cz",ldns.LDNS_RR_TYPE_ANY, ldns.LDNS_RR_CLASS_IN, ldns.LDNS_QR | ldns.LDNS_AA)
>>> rra = ldns.ldns_rr.new_frm_str("test.nic.cz. IN A 192.168.1.1",300)
>>> list = ldns.ldns_rr_list()
>>> if (rra): list.push_rr(rra)
>>> pkt.push_rr_list(ldns.LDNS_SECTION_ANSWER, list)
>>> print pkt
;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 0
;; flags: qr aa ; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;; test.nic.cz. IN ANY
;; ANSWER SECTION:
test.nic.cz. 300 IN A 192.168.1.1
;; AUTHORITY SECTION:
;; ADDITIONAL SECTION:
;; Query time: 0 msec
;; WHEN: Thu Jan 1 01:00:00 1970
;; MSG SIZE rcvd: 0
Return the packet’s ns count.
Returns: | (uint16_t) The ns count. |
---|
Converts a packet opcode to its mnemonic and returns that as an allocated null-terminated string.
Returns: | (str) |
---|
Prints the data in the DNS packet to the given file stream (in presentation format).
Parameters: | output (file) – Opened file to write to. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Push an rr on a packet.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (bool) A boolean which is True when the rr was added. |
Push a rr_list on a packet.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (bool) A boolean which is True when the rr was added. |
Return the packet’s qd count.
Returns: | (uint16_t) The qd count. |
---|
Read the packet’s qr bit.
Returns: | (bool) value of the bit |
---|
Return the packet’s query time.
Returns: | (uint32_t) The query time. |
---|
Return the packet’s question section.
Returns: | (ldns_rr_list) The question section. |
---|
Read the packet’s ra bit.
Returns: | (bool) Value of the bit. |
---|
Converts a packet rcode to its mnemonic and returns that as an allocated null-terminated string.
Returns: | (str) |
---|
Read the packet’s rd bit.
Returns: | (bool) Value of the bit. |
---|
Looks inside the packet to determine what kind of packet it is, AUTH, NXDOMAIN, REFERRAL, etc.
Returns: | (ldns_pkt_type) The type of packet. |
---|
Check to see if an rr exist in the packet.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (bool) Return True is exists. |
Return all the rr with a specific name from a packet.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (ldns_rr_list) A list with the rr’s or None if none were found. |
Return all the rr with a specific type and type from a packet.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (ldns_rr_list) A list with the rr’s or None if none were found. |
Return all the rr with a specific type from a packet.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (ldns_rr_list) A list with the rr’s or None if none were found. |
Push an rr on a packet, provided the RR is not there.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (bool) A boolean which is True when the rr was added. |
Push an rr_list to a packet, provided the RRs are not already there.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (bool) A boolean which is True when the list was added. |
Set the packet’s aa bit.
Parameters: | b (bool) – The value to set. |
---|
Set the packet’s ad bit.
Parameters: | b (bool) – The value to set. |
---|
Directly set the additional section.
Parameters: | rr (ldns_rr_list) – The rr list to set. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s an count.
Parameters: | c (int) – The count. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Directly set the answer section.
Parameters: | rr (ldns_rr_list) – The rr list to set. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s answering server.
Parameters: | r (ldns_rdf) – The address. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s arcount.
Parameters: | c (int) – The count. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Directly set the authority section.
Parameters: | rr (ldns_rr_list) – The rr list to set. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s cd bit.
Parameters: | b (bool) – The value to set. |
---|
Set the packet’s edns data.
Parameters: | data (ldns_rdf) – The data. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s edns do bit.
Parameters: | value (bool) – The bit’s new value. |
---|
Set the packet’s edns extended rcode.
Parameters: | c (uint8_t) – The code. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s edns udp size.
Parameters: | s (uint16_t) – The size. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s edns version.
Parameters: | v (uint8_t) – The version. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s edns z value.
Parameters: | z (uint16_t) – The value. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Sets the flags in a packet.
Parameters: | flags (int) – ORed values: LDNS_QR| LDNS_AR for instance. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. | |
Returns: | (bool) True on success, False otherwise. |
Set the packet’s id.
Parameters: | id (uint16_t) – The id to set. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s ns count.
Parameters: | c (int) – The count. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s opcode.
Parameters: | c (ldns_pkt_opcode) – The opcode. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s qd count.
Parameters: | c (int) – The count. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s qr bit.
Parameters: | b (bool) – The value to set. |
---|
Set the packet’s query time.
Parameters: | t (uint32_t) – The query time in msec. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Directly set the question section.
Parameters: | rr (ldns_rr_list) – The rr list to set. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s ra bit.
Parameters: | b (bool) – The value to set. |
---|
Set the packet’s id to a random value.
Set the packet’s respons code.
Parameters: | c (uint8_t) – The rcode. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s rd bit.
Parameters: | b (bool) – The value to set. |
---|
Set a packet’s section count to x.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s size.
Parameters: | s (int) – The size. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s tc bit.
Parameters: | b (bool) – The value to set. |
---|
Set the packet’s time stamp.
Parameters: | timestamp (struct timeval) – The time stamp. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the packet’s tsig rr.
Parameters: | t (ldns_rr) – The tsig rr. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Return the packet’s size in bytes.
Returns: | (size_t) The size. |
---|
Read the packet’s tc bit.
Returns: | (bool) Value of the bit. |
---|
Return the packet’s time stamp.
Returns: | (struct timeval) The time stamp. |
---|
Get the ad count.
Returns: | (uint16_t) The ad count. |
---|
Add tsig credentials to a packet from a resolver.
Parameters: | r (ldns_resolver) – Resolver to copy from. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. | |
Returns: | (ldns_status) Status whether successful or not. |
Get the pr count.
Returns: | (uint16_t) The pr count. |
---|
Set the ad count.
Parameters: | c (uint16_t) – The ad count to set. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the pr count.
Parameters: | c (uint16_t) – The pr count to set. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the up count.
Parameters: | c (uint16_t) – The up count to set. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the zo count.
Parameters: | c (uint16_t) – The zo count to set. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Get the up count.
Returns: | (uint16_t) The up count. |
---|
Get the zo count.
Returns: | (uint16_t) The zo count. |
---|
Copies the packet data to the buffer in wire format.
Parameters: | buffer (ldns_buffer) – Buffer to append the result to. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. | |
Returns: | (ldns_status) ldns_status |