Python dns.exception() Examples
The following are 30
code examples of dns.exception().
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: blockcheck.py From blockcheck with MIT License | 7 votes |
def _get_a_record(site, querytype='A', dnsserver=None): resolver = dns.resolver.Resolver() resolver.timeout = 5 resolver.lifetime = 5 if dnsserver: resolver.nameservers = [dnsserver] result = [] while len(resolver.nameservers): try: resolved = resolver.query(site, querytype) print_debug(str(resolved.response)) for item in resolved.rrset.items: result.append(item.to_text()) return result except dns.exception.Timeout: print_debug("DNS Timeout for", site, "using", resolver.nameservers[0]) resolver.nameservers.remove(resolver.nameservers[0]) # If all the requests failed return ""
Example #2
Source File: zone.py From bazarr with GNU General Public License v3.0 | 6 votes |
def get_node(self, name, create=False): """Get a node in the zone, possibly creating it. This method is like L{find_node}, except it returns None instead of raising an exception if the node does not exist and creation has not been requested. @param name: the name of the node to find @type name: dns.name.Name object or string @param create: should the node be created if it doesn't exist? @type create: bool @rtype: dns.node.Node object or None """ try: node = self.find_node(name, create) except KeyError: node = None return node
Example #3
Source File: dyn.py From lemur with Apache License 2.0 | 6 votes |
def _has_dns_propagated(fqdn, token): txt_records = [] try: dns_resolver = dns.resolver.Resolver() dns_resolver.nameservers = [get_authoritative_nameserver(fqdn)] dns_response = dns_resolver.query(fqdn, "TXT") for rdata in dns_response: for txt_record in rdata.strings: txt_records.append(txt_record.decode("utf-8")) except dns.exception.DNSException: metrics.send("has_dns_propagated_fail", "counter", 1, metric_tags={"dns": fqdn}) return False for txt_record in txt_records: if txt_record == token: metrics.send("has_dns_propagated_success", "counter", 1, metric_tags={"dns": fqdn}) return True return False
Example #4
Source File: name.py From arissploit with GNU General Public License v3.0 | 6 votes |
def to_digestable(self, origin=None): """Convert name to a format suitable for digesting in hashes. The name is canonicalized and converted to uncompressed wire format. @param origin: If the name is relative and origin is not None, then origin will be appended to it. @type origin: dns.name.Name object @raises NeedAbsoluteNameOrOrigin: All names in wire format are absolute. If self is a relative name, then an origin must be supplied; if it is missing, then this exception is raised @rtype: string """ if not self.is_absolute(): if origin is None or not origin.is_absolute(): raise NeedAbsoluteNameOrOrigin labels = list(self.labels) labels.extend(list(origin.labels)) else: labels = self.labels dlabels = [struct.pack('!B%ds' % len(x), len(x), x.lower()) for x in labels] return b''.join(dlabels)
Example #5
Source File: zone.py From arissploit with GNU General Public License v3.0 | 6 votes |
def get_node(self, name, create=False): """Get a node in the zone, possibly creating it. This method is like L{find_node}, except it returns None instead of raising an exception if the node does not exist and creation has not been requested. @param name: the name of the node to find @type name: dns.name.Name object or string @param create: should the node be created if it doesn't exist? @type create: bool @rtype: dns.node.Node object or None """ try: node = self.find_node(name, create) except KeyError: node = None return node
Example #6
Source File: name.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def to_digestable(self, origin=None): """Convert name to a format suitable for digesting in hashes. The name is canonicalized and converted to uncompressed wire format. @param origin: If the name is relative and origin is not None, then origin will be appended to it. @type origin: dns.name.Name object @raises NeedAbsoluteNameOrOrigin: All names in wire format are absolute. If self is a relative name, then an origin must be supplied; if it is missing, then this exception is raised @rtype: string """ if not self.is_absolute(): if origin is None or not origin.is_absolute(): raise NeedAbsoluteNameOrOrigin labels = list(self.labels) labels.extend(list(origin.labels)) else: labels = self.labels dlabels = [struct.pack('!B%ds' % len(x), len(x), x.lower()) for x in labels] return b''.join(dlabels)
Example #7
Source File: blockcheck.py From blockcheck with MIT License | 6 votes |
def _get_a_records(sitelist, querytype='A', dnsserver=None, googleapi=False): result = [] for site in sorted(sitelist): try: if googleapi: responses = _get_a_record_over_google_api(site, querytype) print_debug("Google API вернул {}".format(responses)) else: responses = _get_a_record(site, querytype, dnsserver) for item in responses: result.append(item) except dns.resolver.NXDOMAIN: print("[!] Невозможно получить DNS-запись для домена {} (NXDOMAIN). Результаты могут быть неточными.".format(site)) except dns.resolver.NoAnswer: print_debug("DNS NoAnswer:", site) except dns.exception.DNSException as e: print_debug("DNSException:", str(e)) really_bad_fuckup_happened() return sorted(result)
Example #8
Source File: zone.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def get_node(self, name, create=False): """Get a node in the zone, possibly creating it. This method is like L{find_node}, except it returns None instead of raising an exception if the node does not exist and creation has not been requested. @param name: the name of the node to find @type name: dns.name.Name object or string @param create: should the node be created if it doesn't exist? @type create: bool @rtype: dns.node.Node object or None """ try: node = self.find_node(name, create) except KeyError: node = None return node
Example #9
Source File: tokenizer.py From arissploit with GNU General Public License v3.0 | 6 votes |
def get_uint32(self): """Read the next token and interpret it as a 32-bit unsigned integer. @raises dns.exception.SyntaxError: @rtype: int """ token = self.get().unescape() if not token.is_identifier(): raise dns.exception.SyntaxError('expecting an identifier') if not token.value.isdigit(): raise dns.exception.SyntaxError('expecting an integer') value = long(token.value) if value < 0 or value > long(4294967296): raise dns.exception.SyntaxError( '%d is not an unsigned 32-bit integer' % value) return value
Example #10
Source File: tokenizer.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def get_uint32(self): """Read the next token and interpret it as a 32-bit unsigned integer. @raises dns.exception.SyntaxError: @rtype: int """ token = self.get().unescape() if not token.is_identifier(): raise dns.exception.SyntaxError('expecting an identifier') if not token.value.isdigit(): raise dns.exception.SyntaxError('expecting an integer') value = long(token.value) if value < 0 or value > long(4294967296): raise dns.exception.SyntaxError( '%d is not an unsigned 32-bit integer' % value) return value
Example #11
Source File: name.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def to_digestable(self, origin=None): """Convert name to a format suitable for digesting in hashes. The name is canonicalized and converted to uncompressed wire format. @param origin: If the name is relative and origin is not None, then origin will be appended to it. @type origin: dns.name.Name object @raises NeedAbsoluteNameOrOrigin: All names in wire format are absolute. If self is a relative name, then an origin must be supplied; if it is missing, then this exception is raised @rtype: string """ if not self.is_absolute(): if origin is None or not origin.is_absolute(): raise NeedAbsoluteNameOrOrigin labels = list(self.labels) labels.extend(list(origin.labels)) else: labels = self.labels dlabels = [struct.pack('!B%ds' % len(x), len(x), x.lower()) for x in labels] return b''.join(dlabels)
Example #12
Source File: zone.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def get_node(self, name, create=False): """Get a node in the zone, possibly creating it. This method is like L{find_node}, except it returns None instead of raising an exception if the node does not exist and creation has not been requested. @param name: the name of the node to find @type name: dns.name.Name object or string @param create: should the node be created if it doesn't exist? @type create: bool @rtype: dns.node.Node object or None """ try: node = self.find_node(name, create) except KeyError: node = None return node
Example #13
Source File: tokenizer.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def get_uint32(self): """Read the next token and interpret it as a 32-bit unsigned integer. @raises dns.exception.SyntaxError: @rtype: int """ token = self.get().unescape() if not token.is_identifier(): raise dns.exception.SyntaxError('expecting an identifier') if not token.value.isdigit(): raise dns.exception.SyntaxError('expecting an integer') value = long(token.value) if value < 0 or value > long(4294967296): raise dns.exception.SyntaxError( '%d is not an unsigned 32-bit integer' % value) return value
Example #14
Source File: query.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def _wait_for(fd, readable, writable, error, expiration): done = False while not done: if expiration is None: timeout = None else: timeout = expiration - time.time() if timeout <= 0.0: raise dns.exception.Timeout try: if not _polling_backend(fd, readable, writable, error, timeout): raise dns.exception.Timeout except select_error as e: if e.args[0] != errno.EINTR: raise e done = True
Example #15
Source File: tokenizer.py From bazarr with GNU General Public License v3.0 | 6 votes |
def get_uint32(self): """Read the next token and interpret it as a 32-bit unsigned integer. @raises dns.exception.SyntaxError: @rtype: int """ token = self.get().unescape() if not token.is_identifier(): raise dns.exception.SyntaxError('expecting an identifier') if not token.value.isdigit(): raise dns.exception.SyntaxError('expecting an integer') value = long(token.value) if value < 0 or value > long(4294967296): raise dns.exception.SyntaxError( '%d is not an unsigned 32-bit integer' % value) return value
Example #16
Source File: tokenizer.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def get_uint32(self): """Read the next token and interpret it as a 32-bit unsigned integer. @raises dns.exception.SyntaxError: @rtype: int """ token = self.get().unescape() if not token.is_identifier(): raise dns.exception.SyntaxError('expecting an identifier') if not token.value.isdigit(): raise dns.exception.SyntaxError('expecting an integer') value = long(token.value) if value < 0 or value > 4294967296L: raise dns.exception.SyntaxError('%d is not an unsigned 32-bit integer' % value) return value
Example #17
Source File: query.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def _wait_for(fd, readable, writable, error, expiration): done = False while not done: if expiration is None: timeout = None else: timeout = expiration - time.time() if timeout <= 0.0: raise dns.exception.Timeout try: if not _polling_backend(fd, readable, writable, error, timeout): raise dns.exception.Timeout except select_error as e: if e.args[0] != errno.EINTR: raise e done = True
Example #18
Source File: name.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def to_digestable(self, origin=None): """Convert name to a format suitable for digesting in hashes. The name is canonicalized and converted to uncompressed wire format. @param origin: If the name is relative and origin is not None, then origin will be appended to it. @type origin: dns.name.Name object @raises NeedAbsoluteNameOrOrigin: All names in wire format are absolute. If self is a relative name, then an origin must be supplied; if it is missing, then this exception is raised @rtype: string """ if not self.is_absolute(): if origin is None or not origin.is_absolute(): raise NeedAbsoluteNameOrOrigin labels = list(self.labels) labels.extend(list(origin.labels)) else: labels = self.labels dlabels = ["%s%s" % (chr(len(x)), x.lower()) for x in labels] return ''.join(dlabels)
Example #19
Source File: name.py From bazarr with GNU General Public License v3.0 | 6 votes |
def to_digestable(self, origin=None): """Convert name to a format suitable for digesting in hashes. The name is canonicalized and converted to uncompressed wire format. @param origin: If the name is relative and origin is not None, then origin will be appended to it. @type origin: dns.name.Name object @raises NeedAbsoluteNameOrOrigin: All names in wire format are absolute. If self is a relative name, then an origin must be supplied; if it is missing, then this exception is raised @rtype: string """ if not self.is_absolute(): if origin is None or not origin.is_absolute(): raise NeedAbsoluteNameOrOrigin labels = list(self.labels) labels.extend(list(origin.labels)) else: labels = self.labels dlabels = [struct.pack('!B%ds' % len(x), len(x), x.lower()) for x in labels] return b''.join(dlabels)
Example #20
Source File: query.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def _wait_for(fd, readable, writable, error, expiration): done = False while not done: if expiration is None: timeout = None else: timeout = expiration - time.time() if timeout <= 0.0: raise dns.exception.Timeout try: if not _polling_backend(fd, readable, writable, error, timeout): raise dns.exception.Timeout except select.error, e: if e.args[0] != errno.EINTR: raise e done = True
Example #21
Source File: zone.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def get_node(self, name, create=False): """Get a node in the zone, possibly creating it. This method is like L{find_node}, except it returns None instead of raising an exception if the node does not exist and creation has not been requested. @param name: the name of the node to find @type name: dns.name.Name object or string @param create: should the node be created if it doesn't exist? @type create: bool @rtype: dns.node.Node object or None """ try: node = self.find_node(name, create) except KeyError: node = None return node
Example #22
Source File: query.py From bazarr with GNU General Public License v3.0 | 6 votes |
def _wait_for(fd, readable, writable, error, expiration): done = False while not done: if expiration is None: timeout = None else: timeout = expiration - time.time() if timeout <= 0.0: raise dns.exception.Timeout try: if not _polling_backend(fd, readable, writable, error, timeout): raise dns.exception.Timeout except select_error as e: if e.args[0] != errno.EINTR: raise e done = True
Example #23
Source File: query.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def _net_read(sock, count, expiration): """Read the specified number of bytes from sock. Keep trying until we either get the desired amount, or we hit EOF. A Timeout exception will be raised if the operation is not completed by the expiration time. """ s = b'' while count > 0: _wait_for_readable(sock, expiration) n = sock.recv(count) if n == b'': raise EOFError count = count - len(n) s = s + n return s
Example #24
Source File: resolver.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def __add__(self, e_nx): """Augment by results from another NXDOMAIN exception.""" qnames0 = list(self.kwargs.get('qnames', [])) responses0 = dict(self.kwargs.get('responses', {})) responses1 = e_nx.kwargs.get('responses', {}) for qname1 in e_nx.kwargs.get('qnames', []): if qname1 not in qnames0: qnames0.append(qname1) if qname1 in responses1: responses0[qname1] = responses1[qname1] return NXDOMAIN(qnames=qnames0, responses=responses0)
Example #25
Source File: tokenizer.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def get_ttl(self): token = self.get().unescape() if not token.is_identifier(): raise dns.exception.SyntaxError('expecting an identifier') return dns.ttl.from_text(token.value)
Example #26
Source File: tokenizer.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def get_name(self, origin=None): """Read the next token and interpret it as a DNS name. @raises dns.exception.SyntaxError: @rtype: dns.name.Name object""" token = self.get() if not token.is_identifier(): raise dns.exception.SyntaxError('expecting an identifier') return dns.name.from_text(token.value, origin)
Example #27
Source File: tokenizer.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def get_uint16(self): """Read the next token and interpret it as a 16-bit unsigned integer. @raises dns.exception.SyntaxError: @rtype: int """ value = self.get_int() if value < 0 or value > 65535: raise dns.exception.SyntaxError( '%d is not an unsigned 16-bit integer' % value) return value
Example #28
Source File: tokenizer.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def get_identifier(self, origin=None): """Read the next token and raise an exception if it is not an identifier. @raises dns.exception.SyntaxError: @rtype: string """ token = self.get().unescape() if not token.is_identifier(): raise dns.exception.SyntaxError('expecting an identifier') return token.value
Example #29
Source File: query.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def _net_write(sock, data, expiration): """Write the specified data to the socket. A Timeout exception will be raised if the operation is not completed by the expiration time. """ current = 0 l = len(data) while current < l: _wait_for_writable(sock, expiration) current += sock.send(data[current:])
Example #30
Source File: tokenizer.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def get_string(self, origin=None): """Read the next token and interpret it as a string. @raises dns.exception.SyntaxError: @rtype: string """ token = self.get().unescape() if not (token.is_identifier() or token.is_quoted_string()): raise dns.exception.SyntaxError('expecting a string') return token.value