Python dns.flags() Examples
The following are 30
code examples of dns.flags().
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: notify.py From designate with Apache License 2.0 | 7 votes |
def _make_dns_message(self, zone_name, notify=False): """ This constructs a SOA query or a dns NOTIFY message. :param zone_name: The zone name for which a SOA/NOTIFY needs to be sent. :param notify: If true, a notify message is constructed else a SOA message is constructed. :return: The constructed message. """ dns_message = dns.message.make_query(zone_name, dns.rdatatype.SOA) dns_message.flags = 0 if notify: dns_message.set_opcode(dns.opcode.NOTIFY) dns_message.flags |= dns.flags.AA else: # Setting the flags to RD causes BIND9 to respond with a NXDOMAIN. dns_message.set_opcode(dns.opcode.QUERY) dns_message.flags |= dns.flags.RD return dns_message
Example #2
Source File: resolver.py From bazarr with GNU General Public License v3.0 | 6 votes |
def reset(self): """Reset all resolver configuration to the defaults.""" self.domain = \ dns.name.Name(dns.name.from_text(socket.gethostname())[1:]) if len(self.domain) == 0: self.domain = dns.name.root self.nameservers = [] self.nameserver_ports = {} self.port = 53 self.search = [] self.timeout = 2.0 self.lifetime = 30.0 self.keyring = None self.keyname = None self.keyalgorithm = dns.tsig.default_algorithm self.edns = -1 self.ednsflags = 0 self.payload = 0 self.cache = None self.flags = None self.retry_servfail = False self.rotate = False
Example #3
Source File: resolver.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def reset(self): """Reset all resolver configuration to the defaults.""" self.domain = \ dns.name.Name(dns.name.from_text(socket.gethostname())[1:]) if len(self.domain) == 0: self.domain = dns.name.root self.nameservers = [] self.nameserver_ports = {} self.port = 53 self.search = [] self.timeout = 2.0 self.lifetime = 30.0 self.keyring = None self.keyname = None self.keyalgorithm = dns.tsig.default_algorithm self.edns = -1 self.ednsflags = 0 self.payload = 0 self.cache = None self.flags = None self.retry_servfail = False self.rotate = False
Example #4
Source File: message.py From bazarr with GNU General Public License v3.0 | 6 votes |
def read(self): """Read a wire format DNS message and build a dns.message.Message object.""" l = len(self.wire) if l < 12: raise ShortHeader (self.message.id, self.message.flags, qcount, ancount, aucount, adcount) = struct.unpack('!HHHHHH', self.wire[:12]) self.current = 12 if dns.opcode.is_update(self.message.flags): self.updating = True self._get_question(qcount) if self.question_only: return self._get_section(self.message.answer, ancount) self._get_section(self.message.authority, aucount) self._get_section(self.message.additional, adcount) if not self.ignore_trailing and self.current != l: raise TrailingJunk if self.message.multi and self.message.tsig_ctx and \ not self.message.had_tsig: self.message.tsig_ctx.update(self.wire)
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: message.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def read(self): """Read a wire format DNS message and build a dns.message.Message object.""" l = len(self.wire) if l < 12: raise ShortHeader (self.message.id, self.message.flags, qcount, ancount, aucount, adcount) = struct.unpack('!HHHHHH', self.wire[:12]) self.current = 12 if dns.opcode.is_update(self.message.flags): self.updating = True self._get_question(qcount) if self.question_only: return self._get_section(self.message.answer, ancount) self._get_section(self.message.authority, aucount) self._get_section(self.message.additional, adcount) if not self.ignore_trailing and self.current != l: raise TrailingJunk if self.message.multi and self.message.tsig_ctx and \ not self.message.had_tsig: self.message.tsig_ctx.update(self.wire)
Example #7
Source File: message.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def read(self): """Read a wire format DNS message and build a dns.message.Message object.""" l = len(self.wire) if l < 12: raise ShortHeader (self.message.id, self.message.flags, qcount, ancount, aucount, adcount) = struct.unpack('!HHHHHH', self.wire[:12]) self.current = 12 if dns.opcode.is_update(self.message.flags): self.updating = True self._get_question(qcount) if self.question_only: return self._get_section(self.message.answer, ancount) self._get_section(self.message.authority, aucount) self._get_section(self.message.additional, adcount) if not self.ignore_trailing and self.current != l: raise TrailingJunk if self.message.multi and self.message.tsig_ctx and \ not self.message.had_tsig: self.message.tsig_ctx.update(self.wire)
Example #8
Source File: resolver.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def reset(self): """Reset all resolver configuration to the defaults.""" self.domain = \ dns.name.Name(dns.name.from_text(socket.gethostname())[1:]) if len(self.domain) == 0: self.domain = dns.name.root self.nameservers = [] self.nameserver_ports = {} self.port = 53 self.search = [] self.timeout = 2.0 self.lifetime = 30.0 self.keyring = None self.keyname = None self.keyalgorithm = dns.tsig.default_algorithm self.edns = -1 self.ednsflags = 0 self.payload = 0 self.cache = None self.flags = None self.retry_servfail = False self.rotate = False
Example #9
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 #10
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 #11
Source File: resolver.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def reset(self): """Reset all resolver configuration to the defaults.""" self.domain = \ dns.name.Name(dns.name.from_text(socket.gethostname())[1:]) if len(self.domain) == 0: self.domain = dns.name.root self.nameservers = [] self.search = [] self.port = 53 self.timeout = 2.0 self.lifetime = 30.0 self.keyring = None self.keyname = None self.keyalgorithm = dns.tsig.default_algorithm self.edns = -1 self.ednsflags = 0 self.payload = 0 self.cache = None self.flags = None self.retry_servfail = False
Example #12
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 #13
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 #14
Source File: message.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def read(self): """Read a wire format DNS message and build a dns.message.Message object.""" l = len(self.wire) if l < 12: raise ShortHeader (self.message.id, self.message.flags, qcount, ancount, aucount, adcount) = struct.unpack('!HHHHHH', self.wire[:12]) self.current = 12 if dns.opcode.is_update(self.message.flags): self.updating = True self._get_question(qcount) if self.question_only: return self._get_section(self.message.answer, ancount) self._get_section(self.message.authority, aucount) self._get_section(self.message.additional, adcount) if not self.ignore_trailing and self.current != l: raise TrailingJunk if self.message.multi and self.message.tsig_ctx and \ not self.message.had_tsig: self.message.tsig_ctx.update(self.wire)
Example #15
Source File: dnsrecon.py From Yuki-Chan-The-Auto-Pentest with MIT License | 6 votes |
def query_ds(target, ns, timeout=5.0): """ Function for performing DS Record queries. Returns answer object. Since a timeout will break the DS NSEC chain of a zone walk it will exit if a timeout happens. """ try: query = dns.message.make_query(target, dns.rdatatype.DS, dns.rdataclass.IN) query.flags += dns.flags.CD query.use_edns(edns=True, payload=4096) query.want_dnssec(True) answer = dns.query.udp(query, ns, timeout) except dns.exception.Timeout: print_error("A timeout error occurred please make sure you can reach the target DNS Servers") print_error( "directly and requests are not being filtered. Increase the timeout from {0} second".format(timeout)) print_error("to a higher number with --lifetime <time> option.") sys.exit(1) except: print("Unexpected error: {0}".format(sys.exc_info()[0])) raise return answer
Example #16
Source File: dnsrecon.py From Yuki-Chan-The-Auto-Pentest with MIT License | 6 votes |
def check_recursive(ns_server, timeout): """ Check if a NS Server is recursive. """ is_recursive = False query = dns.message.make_query('www.google.com.', dns.rdatatype.NS) try: response = dns.query.udp(query, ns_server, timeout) recursion_flag_pattern = "\.*RA\.*" flags = dns.flags.to_text(response.flags) result = re.findall(recursion_flag_pattern, flags) if (result): print_error("\t Recursion enabled on NS Server {0}".format(ns_server)) is_recursive = True except (socket.error, dns.exception.Timeout): return is_recursive return is_recursive
Example #17
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 #18
Source File: resolver.py From bazarr with GNU General Public License v3.0 | 5 votes |
def __init__(self, filename='/etc/resolv.conf', configure=True): """Initialize a resolver instance. @param filename: The filename of a configuration file in standard /etc/resolv.conf format. This parameter is meaningful only when I{configure} is true and the platform is POSIX. @type filename: string or file object @param configure: If True (the default), the resolver instance is configured in the normal fashion for the operating system the resolver is running on. (I.e. a /etc/resolv.conf file on POSIX systems and from the registry on Windows systems.) @type configure: bool""" self.domain = None self.nameservers = None self.nameserver_ports = None self.port = None self.search = None self.timeout = None self.lifetime = None self.keyring = None self.keyname = None self.keyalgorithm = None self.edns = None self.ednsflags = None self.payload = None self.cache = None self.flags = None self.retry_servfail = False self.rotate = False self.reset() if configure: if sys.platform == 'win32': self.read_registry() elif filename: self.read_resolv_conf(filename)
Example #19
Source File: resolver.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def use_edns(self, edns, ednsflags, payload): """Configure Edns. @param edns: The EDNS level to use. The default is -1, no Edns. @type edns: int @param ednsflags: The EDNS flags @type ednsflags: int @param payload: The EDNS payload size. The default is 0. @type payload: int""" if edns is None: edns = -1 self.edns = edns self.ednsflags = ednsflags self.payload = payload
Example #20
Source File: message.py From bazarr with GNU General Public License v3.0 | 5 votes |
def opcode(self): """Return the opcode. @rtype: int """ return dns.opcode.from_flags(self.flags)
Example #21
Source File: message.py From bazarr with GNU General Public License v3.0 | 5 votes |
def __init__(self, id=None): if id is None: self.id = dns.entropy.random_16() else: self.id = id self.flags = 0 self.question = [] self.answer = [] self.authority = [] self.additional = [] self.edns = -1 self.ednsflags = 0 self.payload = 0 self.options = [] self.request_payload = 0 self.keyring = None self.keyname = None self.keyalgorithm = dns.tsig.default_algorithm self.request_mac = '' self.other_data = '' self.tsig_error = 0 self.fudge = 300 self.original_id = self.id self.mac = '' self.xfr = False self.origin = None self.tsig_ctx = None self.had_tsig = False self.multi = False self.first = True self.index = {}
Example #22
Source File: resolver.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def _getnameinfo(sockaddr, flags=0): host = sockaddr[0] port = sockaddr[1] if len(sockaddr) == 4: scope = sockaddr[3] family = socket.AF_INET6 else: scope = None family = socket.AF_INET tuples = _getaddrinfo(host, port, family, socket.SOCK_STREAM, socket.SOL_TCP, 0) if len(tuples) > 1: raise socket.error('sockaddr resolved to multiple addresses') addr = tuples[0][4][0] if flags & socket.NI_DGRAM: pname = 'udp' else: pname = 'tcp' qname = dns.reversename.from_address(addr) if flags & socket.NI_NUMERICHOST == 0: try: answer = _resolver.query(qname, 'PTR') hostname = answer.rrset[0].target.to_text(True) except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer): if flags & socket.NI_NAMEREQD: raise socket.gaierror(socket.EAI_NONAME) hostname = addr if scope is not None: hostname += '%' + str(scope) else: hostname = addr if scope is not None: hostname += '%' + str(scope) if flags & socket.NI_NUMERICSERV: service = str(port) else: service = socket.getservbyport(port, pname) return (hostname, service)
Example #23
Source File: message.py From bazarr with GNU General Public License v3.0 | 5 votes |
def __eq__(self, other): """Two messages are equal if they have the same content in the header, question, answer, and authority sections. @rtype: bool""" if not isinstance(other, Message): return False if self.id != other.id: return False if self.flags != other.flags: return False 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 for n in self.answer: if n not in other.answer: return False for n in other.answer: if n not in self.answer: return False for n in self.authority: if n not in other.authority: return False for n in other.authority: if n not in self.authority: return False return True
Example #24
Source File: message.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def set_opcode(self, opcode): """Set the opcode. @param opcode: the opcode @type opcode: int """ self.flags &= 0x87FF self.flags |= dns.opcode.to_flags(opcode)
Example #25
Source File: message.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def __eq__(self, other): """Two messages are equal if they have the same content in the header, question, answer, and authority sections. @rtype: bool""" if not isinstance(other, Message): return False if self.id != other.id: return False if self.flags != other.flags: return False 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 for n in self.answer: if n not in other.answer: return False for n in other.answer: if n not in self.answer: return False for n in self.authority: if n not in other.authority: return False for n in other.authority: if n not in self.authority: return False return True
Example #26
Source File: message.py From bazarr with GNU General Public License v3.0 | 5 votes |
def make_response(query, recursion_available=False, our_payload=8192, fudge=300): """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. @param query: the query to respond to @type query: dns.message.Message object @param recursion_available: should RA be set in the response? @type recursion_available: bool @param our_payload: payload size to advertise in EDNS responses; default is 8192. @type our_payload: int @param fudge: TSIG time fudge; default is 300 seconds. @type fudge: int @rtype: dns.message.Message object""" if query.flags & dns.flags.QR: raise dns.exception.FormError('specified query message is not a query') response = dns.message.Message(query.id) response.flags = dns.flags.QR | (query.flags & dns.flags.RD) if recursion_available: response.flags |= dns.flags.RA response.set_opcode(query.opcode()) response.question = list(query.question) if query.edns >= 0: response.use_edns(0, 0, our_payload, query.payload) if query.had_tsig: response.use_tsig(query.keyring, query.keyname, fudge, None, 0, '', query.keyalgorithm) response.request_mac = query.mac return response
Example #27
Source File: message.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def __init__(self, id=None): if id is None: self.id = dns.entropy.random_16() else: self.id = id self.flags = 0 self.question = [] self.answer = [] self.authority = [] self.additional = [] self.edns = -1 self.ednsflags = 0 self.payload = 0 self.options = [] self.request_payload = 0 self.keyring = None self.keyname = None self.keyalgorithm = dns.tsig.default_algorithm self.request_mac = '' self.other_data = '' self.tsig_error = 0 self.fudge = 300 self.original_id = self.id self.mac = '' self.xfr = False self.origin = None self.tsig_ctx = None self.had_tsig = False self.multi = False self.first = True self.index = {}
Example #28
Source File: message.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def make_response(query, recursion_available=False, our_payload=8192): """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. @param query: the query to respond to @type query: dns.message.Message object @param recursion_available: should RA be set in the response? @type recursion_available: bool @param our_payload: payload size to advertise in EDNS responses; default is 8192. @type our_payload: int @rtype: dns.message.Message object""" if query.flags & dns.flags.QR: raise dns.exception.FormError('specified query message is not a query') response = dns.message.Message(query.id) response.flags = dns.flags.QR | (query.flags & dns.flags.RD) if recursion_available: response.flags |= dns.flags.RA response.set_opcode(query.opcode()) response.question = list(query.question) if query.edns >= 0: response.use_edns(0, 0, our_payload, query.payload) if not query.keyname is None: response.keyname = query.keyname response.keyring = query.keyring response.request_mac = query.mac return response
Example #29
Source File: resolver.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def _getnameinfo(sockaddr, flags=0): host = sockaddr[0] port = sockaddr[1] if len(sockaddr) == 4: scope = sockaddr[3] family = socket.AF_INET6 else: scope = None family = socket.AF_INET tuples = _getaddrinfo(host, port, family, socket.SOCK_STREAM, socket.SOL_TCP, 0) if len(tuples) > 1: raise socket.error('sockaddr resolved to multiple addresses') addr = tuples[0][4][0] if flags & socket.NI_DGRAM: pname = 'udp' else: pname = 'tcp' qname = dns.reversename.from_address(addr) if flags & socket.NI_NUMERICHOST == 0: try: answer = _resolver.query(qname, 'PTR') hostname = answer.rrset[0].target.to_text(True) except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer): if flags & socket.NI_NAMEREQD: raise socket.gaierror(socket.EAI_NONAME) hostname = addr if scope is not None: hostname += '%' + str(scope) else: hostname = addr if scope is not None: hostname += '%' + str(scope) if flags & socket.NI_NUMERICSERV: service = str(port) else: service = socket.getservbyport(port, pname) return (hostname, service)
Example #30
Source File: resolver.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def use_edns(self, edns, ednsflags, payload): """Configure Edns. @param edns: The EDNS level to use. The default is -1, no Edns. @type edns: int @param ednsflags: The EDNS flags @type ednsflags: int @param payload: The EDNS payload size. The default is 0. @type payload: int""" if edns is None: edns = -1 self.edns = edns self.ednsflags = ednsflags self.payload = payload