Python dns.name() Examples
The following are 30
code examples of dns.name().
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: domain.py From PowerDNS-Admin with MIT License | 10 votes |
def before_request(): # Check if user is anonymous g.user = current_user login_manager.anonymous_user = Anonymous # Check site is in maintenance mode maintenance = Setting().get('maintenance') if maintenance and current_user.is_authenticated and current_user.role.name not in [ 'Administrator', 'Operator' ]: return render_template('maintenance.html') # Manage session timeout session.permanent = True current_app.permanent_session_lifetime = datetime.timedelta( minutes=int(Setting().get('session_timeout'))) session.modified = True
Example #2
Source File: update.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def absent(self, name, rdtype=None): """Require that an owner name (and optionally an rdata type) does not exist as a prerequisite to the execution of the update.""" if isinstance(name, string_types): name = dns.name.from_text(name, None) if rdtype is None: self.find_rrset(self.answer, name, dns.rdataclass.NONE, dns.rdatatype.ANY, dns.rdatatype.NONE, None, True, True) else: if isinstance(rdtype, string_types): rdtype = dns.rdatatype.from_text(rdtype) self.find_rrset(self.answer, name, dns.rdataclass.NONE, rdtype, dns.rdatatype.NONE, None, True, True)
Example #3
Source File: SOA.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): (mname, cused) = dns.name.from_wire(wire[: current + rdlen], current) current += cused rdlen -= cused (rname, cused) = dns.name.from_wire(wire[: current + rdlen], current) current += cused rdlen -= cused if rdlen != 20: raise dns.exception.FormError five_ints = struct.unpack('!IIIII', wire[current : current + rdlen]) if not origin is None: mname = mname.relativize(origin) rname = rname.relativize(origin) return cls(rdclass, rdtype, mname, rname, five_ints[0], five_ints[1], five_ints[2], five_ints[3], five_ints[4])
Example #4
Source File: rrset.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def to_text(self, origin=None, relativize=True, **kw): """Convert the RRset into DNS master file format. @see: L{dns.name.Name.choose_relativity} for more information on how I{origin} and I{relativize} determine the way names are emitted. Any additional keyword arguments are passed on to the rdata to_text() method. @param origin: The origin for relative names, or None. @type origin: dns.name.Name object @param relativize: True if names should names be relativized @type relativize: bool""" return super(RRset, self).to_text(self.name, origin, relativize, self.deleting, **kw)
Example #5
Source File: rrset.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def from_text_list(name, ttl, rdclass, rdtype, text_rdatas): """Create an RRset with the specified name, TTL, class, and type, and with the specified list of rdatas in text format. @rtype: dns.rrset.RRset object """ if isinstance(name, (str, unicode)): name = dns.name.from_text(name, None) if isinstance(rdclass, (str, unicode)): rdclass = dns.rdataclass.from_text(rdclass) if isinstance(rdtype, (str, unicode)): rdtype = dns.rdatatype.from_text(rdtype) r = RRset(name, rdclass, rdtype) r.update_ttl(ttl) for t in text_rdatas: rd = dns.rdata.from_text(r.rdclass, r.rdtype, t) r.add(rd) return r
Example #6
Source File: namedict.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def get_deepest_match(self, name): """Find the deepest match to I{name} in the dictionary. The deepest match is the longest name in the dictionary which is a superdomain of I{name}. @param name: the name @type name: dns.name.Name object @rtype: (key, value) tuple """ depth = len(name) if depth > self.max_depth: depth = self.max_depth for i in xrange(-depth, 0): n = dns.name.Name(name[i:]) if self.has_key(n): return (n, self[n]) v = self[dns.name.empty] return (dns.name.empty, v)
Example #7
Source File: rrset.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def from_rdata_list(name, ttl, rdatas): """Create an RRset with the specified name and TTL, and with the specified list of rdata objects. @rtype: dns.rrset.RRset object """ if isinstance(name, (str, unicode)): name = dns.name.from_text(name, None) if len(rdatas) == 0: raise ValueError("rdata list must not be empty") r = None for rd in rdatas: if r is None: r = RRset(name, rd.rdclass, rd.rdtype) r.update_ttl(ttl) first_time = False r.add(rd) return r
Example #8
Source File: dyn.py From lemur with Apache License 2.0 | 6 votes |
def get_zone_name(domain): zones = get_all_zones() zone_name = "" for z in zones: if domain.endswith(z.name): # Find the most specific zone possible for the domain # Ex: If fqdn is a.b.c.com, there is a zone for c.com, # and a zone for b.c.com, we want to use b.c.com. if z.name.count(".") > zone_name.count("."): zone_name = z.name if not zone_name: metrics.send("dyn_no_zone_name", "counter", 1) raise Exception("No Dyn zone found for domain: {}".format(domain)) return zone_name
Example #9
Source File: update.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def absent(self, name, rdtype=None): """Require that an owner name (and optionally an rdata type) does not exist as a prerequisite to the execution of the update.""" if isinstance(name, (str, unicode)): name = dns.name.from_text(name, None) if rdtype is None: rrset = self.find_rrset(self.answer, name, dns.rdataclass.NONE, dns.rdatatype.ANY, dns.rdatatype.NONE, None, True, True) else: if isinstance(rdtype, (str, unicode)): rdtype = dns.rdatatype.from_text(rdtype) rrset = self.find_rrset(self.answer, name, dns.rdataclass.NONE, rdtype, dns.rdatatype.NONE, None, True, True)
Example #10
Source File: SOA.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): (mname, cused) = dns.name.from_wire(wire[: current + rdlen], current) current += cused rdlen -= cused (rname, cused) = dns.name.from_wire(wire[: current + rdlen], current) current += cused rdlen -= cused if rdlen != 20: raise dns.exception.FormError five_ints = struct.unpack('!IIIII', wire[current: current + rdlen]) if origin is not None: mname = mname.relativize(origin) rname = rname.relativize(origin) return cls(rdclass, rdtype, mname, rname, five_ints[0], five_ints[1], five_ints[2], five_ints[3], five_ints[4])
Example #11
Source File: domain.py From PowerDNS-Admin with MIT License | 6 votes |
def change_soa_edit_api(domain_name): domain = Domain.query.filter(Domain.name == domain_name).first() if not domain: abort(404) new_setting = request.form.get('soa_edit_api') if new_setting is None: abort(500) if new_setting == '0': return redirect(url_for('domain.setting', domain_name=domain_name)) d = Domain() status = d.update_soa_setting(domain_name=domain_name, soa_edit_api=new_setting) if status['status'] == 'ok': history = History( msg='Update soa_edit_api for domain {0}'.format(domain_name), detail=str({ "domain": domain_name, "soa_edit_api": new_setting }), created_by=current_user.username) history.add() return redirect(url_for('domain.setting', domain_name = domain_name)) else: abort(500)
Example #12
Source File: rrset.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def to_text(self, origin=None, relativize=True, **kw): """Convert the RRset into DNS master file format. @see: L{dns.name.Name.choose_relativity} for more information on how I{origin} and I{relativize} determine the way names are emitted. Any additional keyword arguments are passed on to the rdata to_text() method. @param origin: The origin for relative names, or None. @type origin: dns.name.Name object @param relativize: True if names should names be relativized @type relativize: bool""" return super(RRset, self).to_text(self.name, origin, relativize, self.deleting, **kw)
Example #13
Source File: record.py From PowerDNS-Admin with MIT License | 6 votes |
def __init__(self, name=None, type=None, status=None, ttl=None, data=None, comment_data=None): self.name = name self.type = type self.status = status self.ttl = ttl self.data = data self.comment_data = comment_data # PDNS configs self.PDNS_STATS_URL = Setting().get('pdns_api_url') self.PDNS_API_KEY = Setting().get('pdns_api_key') self.PDNS_VERSION = Setting().get('pdns_version') self.API_EXTENDED_URL = utils.pdns_api_extended_uri(self.PDNS_VERSION) self.PRETTY_IPV6_PTR = Setting().get('pretty_ipv6_ptr')
Example #14
Source File: network.py From pytos with Apache License 2.0 | 6 votes |
def get_iana_protocols(): """Parse the local file of IANA IP protocols and return a dictionary of protocol number to name. :rtype:dict[int,str] """ os_dist = platform.system() if os_dist == "Linux": protocols_file_path = "/etc/protocols" elif os_dist == "Windows": protocols_file_path = "C:\\windows\\system32\\etc\\protocols" else: raise TypeError("Unsupported OS '{}'".format(os_dist)) protocols = {} with open(protocols_file_path) as services_file: for line in services_file.readlines(): if not line.startswith("#") and not line.isspace(): _, protocol_number, protocol_name, *_ = line.split() protocols[int(protocol_number)] = protocol_name return protocols
Example #15
Source File: record.py From PowerDNS-Admin with MIT License | 6 votes |
def merge_rrsets(self, rrsets): """ Merge the rrsets that has same "name" and "type". Return: a new rrset which has multiple "records" and "comments" """ if not rrsets: raise Exception("Empty rrsets to merge") elif len(rrsets) == 1: # It is unique rrset already return rrsets[0] else: # Merge rrsets into one rrset = rrsets[0] for r in rrsets[1:]: rrset['records'] = rrset['records'] + r['records'] rrset['comments'] = rrset['comments'] + r['comments'] while len(rrset['comments']) < len(rrset['records']): rrset['comments'].append({"content": "", "account": ""}) zipped_list = zip(rrset['records'], rrset['comments']) tuples = zip(*sorted(zipped_list, key=by_record_content_pair)) rrset['records'], rrset['comments'] = [list(t) for t in tuples] return rrset
Example #16
Source File: rrset.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def from_text_list(name, ttl, rdclass, rdtype, text_rdatas, idna_codec=None): """Create an RRset with the specified name, TTL, class, and type, and with the specified list of rdatas in text format. @rtype: dns.rrset.RRset object """ if isinstance(name, string_types): name = dns.name.from_text(name, None, idna_codec=idna_codec) if isinstance(rdclass, string_types): rdclass = dns.rdataclass.from_text(rdclass) if isinstance(rdtype, string_types): rdtype = dns.rdatatype.from_text(rdtype) r = RRset(name, rdclass, rdtype) r.update_ttl(ttl) for t in text_rdatas: rd = dns.rdata.from_text(r.rdclass, r.rdtype, t) r.add(rd) return r
Example #17
Source File: namedict.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def get_deepest_match(self, name): """Find the deepest match to I{name} in the dictionary. The deepest match is the longest name in the dictionary which is a superdomain of I{name}. @param name: the name @type name: dns.name.Name object @rtype: (key, value) tuple """ depth = len(name) if depth > self.max_depth: depth = self.max_depth for i in xrange(-depth, 0): n = dns.name.Name(name[i:]) if n in self: return (n, self[n]) v = self[dns.name.empty] return (dns.name.empty, v)
Example #18
Source File: rrset.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def from_rdata_list(name, ttl, rdatas, idna_codec=None): """Create an RRset with the specified name and TTL, and with the specified list of rdata objects. @rtype: dns.rrset.RRset object """ if isinstance(name, string_types): name = dns.name.from_text(name, None, idna_codec=idna_codec) if len(rdatas) == 0: raise ValueError("rdata list must not be empty") r = None for rd in rdatas: if r is None: r = RRset(name, rd.rdclass, rd.rdtype) r.update_ttl(ttl) r.add(rd) return r
Example #19
Source File: namedict.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def __setitem__(self, key, value): if not isinstance(key, dns.name.Name): raise ValueError('NameDict key must be a name') depth = len(key) if depth > self.max_depth: self.max_depth = depth super(NameDict, self).__setitem__(key, value)
Example #20
Source File: record.py From PowerDNS-Admin with MIT License | 5 votes |
def delete(self, domain): """ Delete a record from domain """ headers = {'X-API-Key': self.PDNS_API_KEY} data = { "rrsets": [{ "name": self.name.rstrip('.') + '.', "type": self.type, "changetype": "DELETE", "records": [] }] } try: jdata = utils.fetch_json(urljoin( self.PDNS_STATS_URL, self.API_EXTENDED_URL + '/servers/localhost/zones/{0}'.format(domain)), headers=headers, timeout=int( Setting().get('pdns_api_timeout')), method='PATCH', verify=Setting().get('verify_ssl_connections'), data=data) current_app.logger.debug(jdata) return {'status': 'ok', 'msg': 'Record was removed successfully'} except Exception as e: current_app.logger.error( "Cannot remove record {0}/{1}/{2} from domain {3}. DETAIL: {4}" .format(self.name, self.type, self.data, domain, e)) return { 'status': 'error', 'msg': 'There was something wrong, please contact administrator' }
Example #21
Source File: domain.py From PowerDNS-Admin with MIT License | 5 votes |
def change_type(domain_name): domain = Domain.query.filter(Domain.name == domain_name).first() if not domain: abort(404) domain_type = request.form.get('domain_type') if domain_type is None: abort(500) if domain_type == '0': return redirect(url_for('domain.setting', domain_name=domain_name)) #TODO: Validate ip addresses input domain_master_ips = [] if domain_type == 'slave' and request.form.getlist('domain_master_address'): domain_master_string = request.form.getlist( 'domain_master_address')[0] domain_master_string = domain_master_string.replace( ' ', '') domain_master_ips = domain_master_string.split(',') d = Domain() status = d.update_kind(domain_name=domain_name, kind=domain_type, masters=domain_master_ips) if status['status'] == 'ok': history = History(msg='Update type for domain {0}'.format(domain_name), detail=str({ "domain": domain_name, "type": domain_type, "masters": domain_master_ips }), created_by=current_user.username) history.add() return redirect(url_for('domain.setting', domain_name = domain_name)) else: abort(500)
Example #22
Source File: domain.py From PowerDNS-Admin with MIT License | 5 votes |
def change_account(domain_name): domain = Domain.query.filter(Domain.name == domain_name).first() if not domain: abort(404) account_id = request.form.get('accountid') status = Domain(name=domain.name).assoc_account(account_id) if status['status']: return redirect(url_for('domain.setting', domain_name=domain.name)) else: abort(500)
Example #23
Source File: rrset.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def __repr__(self): if self.covers == 0: ctext = '' else: ctext = '(' + dns.rdatatype.to_text(self.covers) + ')' if not self.deleting is None: dtext = ' delete=' + dns.rdataclass.to_text(self.deleting) else: dtext = '' return '<DNS ' + str(self.name) + ' ' + \ dns.rdataclass.to_text(self.rdclass) + ' ' + \ dns.rdatatype.to_text(self.rdtype) + ctext + dtext + ' RRset>'
Example #24
Source File: tsigkeyring.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def to_text(keyring): """Convert a dictionary containing (dns.name.Name, binary secret) pairs into a text keyring which has (textual DNS name, base64 secret) pairs. @rtype: dict""" textring = {} for keyname in keyring: keytext = dns.name.to_text(keyname) secret = base64.encodestring(keyring[keyname]) textring[keytext] = secret return textring
Example #25
Source File: RP.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): (mbox, cused) = dns.name.from_wire(wire[: current + rdlen], current) current += cused rdlen -= cused if rdlen <= 0: raise dns.exception.FormError (txt, cused) = dns.name.from_wire(wire[: current + rdlen], current) if cused != rdlen: raise dns.exception.FormError if not origin is None: mbox = mbox.relativize(origin) txt = txt.relativize(origin) return cls(rdclass, rdtype, mbox, txt)
Example #26
Source File: nsbase.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): (target, cused) = dns.name.from_wire(wire[: current + rdlen], current) if cused != rdlen: raise dns.exception.FormError if not origin is None: target = target.relativize(origin) return cls(rdclass, rdtype, target)
Example #27
Source File: update.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def present(self, name, *args): """Require that an owner name (and optionally an rdata type, or specific rdataset) exists as a prerequisite to the execution of the update. The first argument is always a name. The other arguments can be: - rdataset... - rdata... - rdtype, string...""" if isinstance(name, (str, unicode)): name = dns.name.from_text(name, None) if len(args) == 0: rrset = self.find_rrset(self.answer, name, dns.rdataclass.ANY, dns.rdatatype.ANY, dns.rdatatype.NONE, None, True, True) elif isinstance(args[0], dns.rdataset.Rdataset) or \ isinstance(args[0], dns.rdata.Rdata) or \ len(args) > 1: if not isinstance(args[0], dns.rdataset.Rdataset): # Add a 0 TTL args = list(args) args.insert(0, 0) self._add(False, self.answer, name, *args) else: rdtype = args[0] if isinstance(rdtype, (str, unicode)): rdtype = dns.rdatatype.from_text(rdtype) rrset = self.find_rrset(self.answer, name, dns.rdataclass.ANY, rdtype, dns.rdatatype.NONE, None, True, True)
Example #28
Source File: update.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def add(self, name, *args): """Add records. The first argument is always a name. The other arguments can be: - rdataset... - ttl, rdata... - ttl, rdtype, string...""" self._add(False, self.authority, name, *args)
Example #29
Source File: update.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def _add(self, replace, section, name, *args): """Add records. The first argument is the replace mode. If false, RRs are added to an existing RRset; if true, the RRset is replaced with the specified contents. The second argument is the section to add to. The third argument is always a name. The other arguments can be: - rdataset... - ttl, rdata... - ttl, rdtype, string...""" if isinstance(name, (str, unicode)): name = dns.name.from_text(name, None) if isinstance(args[0], dns.rdataset.Rdataset): for rds in args: if replace: self.delete(name, rds.rdtype) for rd in rds: self._add_rr(name, rds.ttl, rd, section=section) else: args = list(args) ttl = int(args.pop(0)) if isinstance(args[0], dns.rdata.Rdata): if replace: self.delete(name, args[0].rdtype) for rd in args: self._add_rr(name, ttl, rd, section=section) else: rdtype = args.pop(0) if isinstance(rdtype, str): rdtype = dns.rdatatype.from_text(rdtype) if replace: self.delete(name, rdtype) for s in args: rd = dns.rdata.from_text(self.zone_rdclass, rdtype, s, self.origin) self._add_rr(name, ttl, rd, section=section)
Example #30
Source File: update.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def _add_rr(self, name, ttl, rd, deleting=None, section=None): """Add a single RR to the update section.""" if section is None: section = self.authority covers = rd.covers() rrset = self.find_rrset(section, name, self.zone_rdclass, rd.rdtype, covers, deleting, True, True) rrset.add(rd, ttl)