Python dns.rcode() Examples
The following are 30
code examples of dns.rcode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
dns
, or try the search function
.
Example #1
Source File: scenario.py From deckard with BSD 2-Clause "Simplified" License | 6 votes |
def adjust_reply( self, query: dns.message.Message, copy_id: bool = True, copy_query: bool = True ) -> None: answer = dns.message.from_wire(self.message.to_wire(), xfr=self.message.xfr, one_rr_per_rrset=True) answer.use_edns(query.edns, query.ednsflags, options=self.message.options) if copy_id: answer.id = query.id # Copy letter-case if the template has QD if answer.question: answer.question[0].name = query.question[0].name if copy_query: answer.question = query.question # Re-set, as the EDNS might have reset the ext-rcode answer.set_rcode(self.message.rcode()) # sanity check: adjusted answer should be almost the same assert len(answer.answer) == len(self.message.answer) assert len(answer.authority) == len(self.message.authority) assert len(answer.additional) == len(self.message.additional) self.message = answer
Example #2
Source File: message.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def is_response(self, other): """Is other a response to self? @rtype: bool""" if other.flags & dns.flags.QR == 0 or \ self.id != other.id or \ dns.opcode.from_flags(self.flags) != \ dns.opcode.from_flags(other.flags): return False if dns.rcode.from_flags(other.flags, other.ednsflags) != \ dns.rcode.NOERROR: return True if dns.opcode.is_update(self.flags): return True for n in self.question: if n not in other.question: return False for n in other.question: if n not in self.question: return False return True
Example #3
Source File: scenario.py From deckard with BSD 2-Clause "Simplified" License | 6 votes |
def process_match(self): try: self.node["/match_present"] except KeyError: return None fields = set(m.value for m in self.node.match("/match")) if 'all' in fields: fields.remove("all") fields |= set(["opcode", "qtype", "qname", "flags", "rcode", "answer", "authority", "additional"]) if 'question' in fields: fields.remove("question") fields |= set(["qtype", "qname"]) return fields
Example #4
Source File: message.py From arissploit with GNU General Public License v3.0 | 6 votes |
def is_response(self, other): """Is other a response to self? @rtype: bool""" if other.flags & dns.flags.QR == 0 or \ self.id != other.id or \ dns.opcode.from_flags(self.flags) != \ dns.opcode.from_flags(other.flags): return False if dns.rcode.from_flags(other.flags, other.ednsflags) != \ dns.rcode.NOERROR: return True if dns.opcode.is_update(self.flags): return True for n in self.question: if n not in other.question: return False for n in other.question: if n not in self.question: return False return True
Example #5
Source File: message.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def is_response(self, other): """Is other a response to self? @rtype: bool""" if other.flags & dns.flags.QR == 0 or \ self.id != other.id or \ dns.opcode.from_flags(self.flags) != \ dns.opcode.from_flags(other.flags): return False if dns.rcode.from_flags(other.flags, other.ednsflags) != \ dns.rcode.NOERROR: return True if dns.opcode.is_update(self.flags): return True for n in self.question: if n not in other.question: return False for n in other.question: if n not in self.question: return False return True
Example #6
Source File: scenario.py From deckard with BSD 2-Clause "Simplified" License | 6 votes |
def get_rcode(cls, fields): """ From `fields` extracts and returns rcode. Throws `ValueError` if there are more then one rcodes """ rcodes = [] for code in fields: try: rcodes.append(dns.rcode.from_text(code)) except dns.rcode.UnknownRcode: pass if len(rcodes) > 1: raise ValueError("Parse failed, too many rcode values.", rcodes) if not rcodes: return None return rcodes[0]
Example #7
Source File: message.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def is_response(self, other): """Is other a response to self? @rtype: bool""" if other.flags & dns.flags.QR == 0 or \ self.id != other.id or \ dns.opcode.from_flags(self.flags) != \ dns.opcode.from_flags(other.flags): return False if dns.rcode.from_flags(other.flags, other.ednsflags) != \ dns.rcode.NOERROR: return True if dns.opcode.is_update(self.flags): return True for n in self.question: if n not in other.question: return False for n in other.question: if n not in self.question: return False return True
Example #8
Source File: message.py From bazarr with GNU General Public License v3.0 | 6 votes |
def is_response(self, other): """Is other a response to self? @rtype: bool""" if other.flags & dns.flags.QR == 0 or \ self.id != other.id or \ dns.opcode.from_flags(self.flags) != \ dns.opcode.from_flags(other.flags): return False if dns.rcode.from_flags(other.flags, other.ednsflags) != \ dns.rcode.NOERROR: return True if dns.opcode.is_update(self.flags): return True for n in self.question: if n not in other.question: return False for n in other.question: if n not in self.question: return False return True
Example #9
Source File: scenario.py From deckard with BSD 2-Clause "Simplified" License | 6 votes |
def get_rcode(cls, fields): """ From `fields` extracts and returns rcode. Throws `ValueError` if there are more then one rcodes """ rcodes = [] for code in fields: try: rcodes.append(dns.rcode.from_text(code)) except dns.rcode.UnknownRcode: pass if len(rcodes) > 1: raise ValueError("Parse failed, too many rcode values.", rcodes) if not rcodes: return None return rcodes[0]
Example #10
Source File: scenario.py From deckard with BSD 2-Clause "Simplified" License | 6 votes |
def process_match(self): try: self.node["/match_present"] except KeyError: return None fields = set(m.value for m in self.node.match("/match")) if 'all' in fields: fields.remove("all") fields |= set(["opcode", "qtype", "qname", "flags", "rcode", "answer", "authority", "additional"]) if 'question' in fields: fields.remove("question") fields |= set(["qtype", "qname"]) return fields
Example #11
Source File: message.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def is_response(self, other): """Is other a response to self? @rtype: bool""" if other.flags & dns.flags.QR == 0 or \ self.id != other.id or \ dns.opcode.from_flags(self.flags) != \ dns.opcode.from_flags(other.flags): return False if dns.rcode.from_flags(other.flags, other.ednsflags) != \ dns.rcode.NOERROR: return True if dns.opcode.is_update(self.flags): return True for n in self.question: if n not in other.question: return False for n in other.question: if n not in self.question: return False return True
Example #12
Source File: scenario.py From deckard with BSD 2-Clause "Simplified" License | 6 votes |
def adjust_reply( self, query: dns.message.Message, copy_id: bool = True, copy_query: bool = True ) -> None: answer = dns.message.from_wire(self.message.to_wire(), xfr=self.message.xfr, one_rr_per_rrset=True) answer.use_edns(query.edns, query.ednsflags, options=self.message.options) if copy_id: answer.id = query.id # Copy letter-case if the template has QD if answer.question: answer.question[0].name = query.question[0].name if copy_query: answer.question = query.question # Re-set, as the EDNS might have reset the ext-rcode answer.set_rcode(self.message.rcode()) # sanity check: adjusted answer should be almost the same assert len(answer.answer) == len(self.message.answer) assert len(answer.authority) == len(self.message.authority) assert len(answer.additional) == len(self.message.additional) self.message = answer
Example #13
Source File: scenario.py From deckard with BSD 2-Clause "Simplified" License | 5 votes |
def __str__(self): txt = 'ENTRY_BEGIN\n' if self.raw_data is None: txt += 'MATCH {0}\n'.format(' '.join(self.match_fields)) txt += 'ADJUST {0}\n'.format(' '.join(self.adjust_fields)) txt += 'REPLY {rcode} {flags}\n'.format( rcode=dns.rcode.to_text(self.message.rcode()), flags=' '.join([dns.flags.to_text(self.message.flags), dns.flags.edns_to_text(self.message.ednsflags)]) ) for sect_name in ['question', 'answer', 'authority', 'additional']: sect = getattr(self.message, sect_name) if not sect: continue txt += 'SECTION {n}\n'.format(n=sect_name.upper()) for rr in sect: txt += str(rr) txt += '\n' if self.raw_data is not None: txt += 'RAW\n' if self.raw_data: txt += binascii.hexlify(self.raw_data) else: txt += 'NULL' txt += '\n' txt += 'ENTRY_END\n' return txt
Example #14
Source File: scenario.py From deckard with BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self, query: dns.message.Message) -> None: message = dns.message.make_response(query) message.set_rcode(dns.rcode.SERVFAIL) super().__init__(message)
Example #15
Source File: scenario.py From deckard with BSD 2-Clause "Simplified" License | 5 votes |
def process_reply_line(self): """Extracts flags, rcode and opcode from given node and adjust dns message accordingly""" self.fields = [f.value for f in self.node.match("/reply")] if 'DO' in self.fields: self.message.want_dnssec(True) opcode = self.get_opcode(fields=self.fields) rcode = self.get_rcode(fields=self.fields) self.message.flags = self.get_flags(fields=self.fields) if rcode is not None: self.message.set_rcode(rcode) if opcode is not None: self.message.set_opcode(opcode)
Example #16
Source File: matchpart.py From deckard with BSD 2-Clause "Simplified" License | 5 votes |
def match_rcode(exp, got): return compare_val(dns.rcode.to_text(exp.rcode()), dns.rcode.to_text(got.rcode()))
Example #17
Source File: scenario.py From deckard with BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self, query: dns.message.Message) -> None: message = dns.message.make_response(query) message.set_rcode(dns.rcode.SERVFAIL) super().__init__(message)
Example #18
Source File: handler.py From designate with Apache License 2.0 | 5 votes |
def _handle_query_error(self, request, rcode): """ Construct an error response with the rcode passed in. :param request: The decoded request from the wire. :param rcode: The response code to send back. :return: A dns response message with the response code set to rcode """ response = dns.message.make_response(request) response.set_rcode(rcode) return response
Example #19
Source File: message.py From bazarr with GNU General Public License v3.0 | 5 votes |
def rcode(self): """Return the rcode. @rtype: int """ return dns.rcode.from_flags(self.flags, self.ednsflags)
Example #20
Source File: message.py From bazarr with GNU General Public License v3.0 | 5 votes |
def set_rcode(self, rcode): """Set the rcode. @param rcode: the rcode @type rcode: int """ (value, evalue) = dns.rcode.to_flags(rcode) self.flags &= 0xFFF0 self.flags |= value self.ednsflags &= long(0x00FFFFFF) self.ednsflags |= evalue if self.ednsflags != 0 and self.edns < 0: self.edns = 0
Example #21
Source File: message.py From arissploit with GNU General Public License v3.0 | 5 votes |
def rcode(self): """Return the rcode. @rtype: int """ return dns.rcode.from_flags(self.flags, self.ednsflags)
Example #22
Source File: message.py From arissploit with GNU General Public License v3.0 | 5 votes |
def set_rcode(self, rcode): """Set the rcode. @param rcode: the rcode @type rcode: int """ (value, evalue) = dns.rcode.to_flags(rcode) self.flags &= 0xFFF0 self.flags |= value self.ednsflags &= long(0x00FFFFFF) self.ednsflags |= evalue if self.ednsflags != 0 and self.edns < 0: self.edns = 0
Example #23
Source File: message.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def rcode(self): """Return the rcode. @rtype: int """ return dns.rcode.from_flags(self.flags, self.ednsflags)
Example #24
Source File: message.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def set_rcode(self, rcode): """Set the rcode. @param rcode: the rcode @type rcode: int """ (value, evalue) = dns.rcode.to_flags(rcode) self.flags &= 0xFFF0 self.flags |= value self.ednsflags &= long(0x00FFFFFF) self.ednsflags |= evalue if self.ednsflags != 0 and self.edns < 0: self.edns = 0
Example #25
Source File: handler.py From designate with Apache License 2.0 | 5 votes |
def _handle_query_error(request, rcode): """ Construct an error response with the rcode passed in. :param request: The decoded request from the wire. :param rcode: The response code to send back. :return: A dns response message with the response code set to rcode """ response = dns.message.make_response(request) response.set_rcode(rcode) return response
Example #26
Source File: message.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def set_rcode(self, rcode): """Set the rcode. @param rcode: the rcode @type rcode: int """ (value, evalue) = dns.rcode.to_flags(rcode) self.flags &= 0xFFF0 self.flags |= value self.ednsflags &= long(0x00FFFFFF) self.ednsflags |= evalue if self.ednsflags != 0 and self.edns < 0: self.edns = 0
Example #27
Source File: message.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def rcode(self): """Return the rcode. @rtype: int """ return dns.rcode.from_flags(self.flags, self.ednsflags)
Example #28
Source File: handler.py From designate with Apache License 2.0 | 5 votes |
def __call__(self, request): """ :param request: DNS Request Message :return: DNS Response Message """ # TODO(Tim): Handle multiple questions rdtype = request.question[0].rdtype rdclass = request.question[0].rdclass opcode = request.opcode() if opcode == dns.opcode.NOTIFY: response = self._handle_notify(request) elif opcode == pcodes.CC: if rdclass == pcodes.CLASSCC: if rdtype == pcodes.CREATE: response = self._handle_create(request) elif rdtype == pcodes.DELETE: response = self._handle_delete(request) else: response = self._handle_query_error(request, dns.rcode.REFUSED) else: response = self._handle_query_error(request, dns.rcode.REFUSED) else: # Unhandled OpCodes include STATUS, QUERY, IQUERY, UPDATE response = self._handle_query_error(request, dns.rcode.REFUSED) # TODO(Tim): Answer Type 65XXX queries yield response return
Example #29
Source File: handler.py From designate with Apache License 2.0 | 5 votes |
def _create_axfr_renderer(self, request): # Build up a dummy response, we're stealing it's logic for building # the Flags. response = dns.message.make_response(request) response.flags |= dns.flags.AA response.set_rcode(dns.rcode.NOERROR) max_message_size = self._get_max_message_size(request.had_tsig) renderer = dns.renderer.Renderer( response.id, response.flags, max_message_size) for q in request.question: renderer.add_question(q.name, q.rdtype, q.rdclass) return renderer
Example #30
Source File: message.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def set_rcode(self, rcode): """Set the rcode. @param rcode: the rcode @type rcode: int """ (value, evalue) = dns.rcode.to_flags(rcode) self.flags &= 0xFFF0 self.flags |= value self.ednsflags &= 0x00FFFFFFL self.ednsflags |= evalue if self.ednsflags != 0 and self.edns < 0: self.edns = 0