当前位置: 首页>>代码示例>>Python>>正文


Python dns.zone方法代码示例

本文整理汇总了Python中dns.zone方法的典型用法代码示例。如果您正苦于以下问题:Python dns.zone方法的具体用法?Python dns.zone怎么用?Python dns.zone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dns的用法示例。


在下文中一共展示了dns.zone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: query_ds

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
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 
开发者ID:Yukinoshita47,项目名称:Yuki-Chan-The-Auto-Pentest,代码行数:24,代码来源:dnsrecon.py

示例2: test_zone_lock

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def test_zone_lock(self):
        # Initialize a ZoneLock
        lock = dnsutils.ZoneLock(0.1)

        # Ensure there's no lock for different zones
        for zone_name in ['foo.com.', 'bar.com.', 'example.com.']:
            self.assertTrue(lock.acquire(zone_name))

        # Ensure a lock for successive calls for the same zone
        self.assertTrue(lock.acquire('example2.com.'))
        self.assertFalse(lock.acquire('example2.com.'))

        # Acquire, release, and reacquire
        self.assertTrue(lock.acquire('example3.com.'))
        lock.release('example3.com.')
        self.assertTrue(lock.acquire('example3.com.')) 
开发者ID:openstack,项目名称:designate,代码行数:18,代码来源:test_dnsutils.py

示例3: acquire

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def acquire(self, zone):
        with self.lock:
            # If no one holds the lock for the zone, grant it
            if zone not in self.data:
                self.data[zone] = time.time()
                return True

            # Otherwise, get the time that it was locked
            locktime = self.data[zone]
            now = time.time()

            period = now - locktime

            # If it has been locked for longer than the allowed period
            # give the lock to the new requester
            if period > self.delay:
                self.data[zone] = now
                return True

            LOG.debug('Lock for %(zone)s can\'t be released for %(period)s'
                      'seconds' % {'zone': zone,
                                   'period': str(self.delay - period)})

            # Don't grant the lock for the zone
            return False 
开发者ID:openstack,项目名称:designate,代码行数:27,代码来源:dnsutils.py

示例4: test_populate

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def test_populate(self, from_xfr_mock):
        got = Zone('unit.tests.', [])

        from_xfr_mock.side_effect = [
            self.forward_zonefile,
            DNSException
        ]

        self.source.populate(got)
        self.assertEquals(11, len(got.records))

        with self.assertRaises(AxfrSourceZoneTransferFailed) as ctx:
            zone = Zone('unit.tests.', [])
            self.source.populate(zone)
        self.assertEquals('Unable to Perform Zone Transfer',
                          text_type(ctx.exception)) 
开发者ID:github,项目名称:octodns,代码行数:18,代码来源:test_octodns_source_axfr.py

示例5: update_resource_record

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def update_resource_record(zone_id, host_name, hosted_zone_name, rectype, changerec, ttl, action):
    if not (rectype == 'NS' and host_name == '@'):
        print 'Updating as %s for %s record %s TTL %s in zone %s with %s ' % (
            action, rectype, host_name, ttl, hosted_zone_name, changerec)
        if rectype != 'SOA':
            if host_name == '@':
                host_name = ''
            elif host_name[-1] != '.':
                host_name += '.'
                # Make Route 53 change record set API call
        dns_changes = {
            'Comment': 'Managed by Lambda Mirror DNS',
            'Changes': [
                {
                    'Action': action,
                    'ResourceRecordSet': {
                        'Name': host_name + hosted_zone_name,
                        'Type': rectype,
                        'ResourceRecords': [],
                        'TTL': ttl
                    }
                }
            ]
        }


        for value in changerec:  # Build the recordset
            if (rectype != 'CNAME' and rectype != 'SRV' and rectype != 'MX' and rectype!= 'NS') or (str(value)[-1] == '.'):
                dns_changes['Changes'][0]['ResourceRecordSet']['ResourceRecords'].append({'Value': str(value)})
            else:
                dns_changes['Changes'][0]['ResourceRecordSet']['ResourceRecords'].append({'Value': str(value) + '.' + hosted_zone_name + '.'})

        try:  # Submit API request to Route 53
            route53.change_resource_record_sets(HostedZoneId=zone_id, ChangeBatch=dns_changes)
        except BaseException as e:
            print e
            sys.exit('ERROR: Unable to update zone %s' % hosted_zone_name)
        return True


# Perform a diff against the two zones and return difference set 
开发者ID:aws-samples,项目名称:aws-lambda-mirror-dns-function,代码行数:43,代码来源:lambda_function.py

示例6: in_cache

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def in_cache(dict_file, ns):
    """
    Function for Cache Snooping, it will check a given NS server for specific
    type of records for a given domain are in it's cache.
    """
    found_records = []
    with open(dict_file) as f:

        for zone in f:
            dom_to_query = str.strip(zone)
            query = dns.message.make_query(dom_to_query, dns.rdatatype.A, dns.rdataclass.IN)
            query.flags ^= dns.flags.RD
            answer = dns.query.udp(query, ns)
            if len(answer.answer) > 0:
                for an in answer.answer:
                    for rcd in an:
                        if rcd.rdtype == 1:
                            print_status("\tName: {0} TTL: {1} Address: {2} Type: A".format(an.name, an.ttl, rcd.address))

                            found_records.extend([{'type': "A", 'name': an.name,
                                                   'address': rcd.address, 'ttl': an.ttl}])

                        elif rcd.rdtype == 5:
                            print_status("\tName: {0} TTL: {1} Target: {2} Type: CNAME".format(an.name, an.ttl, rcd.target))
                            found_records.extend([{'type': "CNAME", 'name': an.name,
                                                   'target': rcd.target, 'ttl': an.ttl}])

                        else:
                            print_status()
    return found_records 
开发者ID:Yukinoshita47,项目名称:Yuki-Chan-The-Auto-Pentest,代码行数:32,代码来源:dnsrecon.py

示例7: dns_sec_check

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def dns_sec_check(domain, res):
    """
    Check if a zone is configured for DNSSEC and if so if NSEC or NSEC3 is used.
    """
    try:
        answer = res._res.query(domain, 'DNSKEY')
        print_status("DNSSEC is configured for {0}".format(domain))
        nsectype = get_nsec_type(domain, res)
        print_status("DNSKEYs:")
        for rdata in answer:
            if rdata.flags == 256:
                key_type = "ZSK"

            if rdata.flags == 257:
                key_type = "KSk"

            print_status("\t{0} {1} {2} {3}".format(nsectype, key_type, algorithm_to_text(rdata.algorithm),
                                                    dns.rdata._hexify(rdata.key)))

    except dns.resolver.NXDOMAIN:
        print_error("Could not resolve domain: {0}".format(domain))
        sys.exit(1)

    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(
            res._res.timeout))
        print_error("to a higher number with --lifetime <time> option.")
        sys.exit(1)
    except dns.resolver.NoAnswer:
        print_error("DNSSEC is not configured for {0}".format(domain)) 
开发者ID:Yukinoshita47,项目名称:Yuki-Chan-The-Auto-Pentest,代码行数:33,代码来源:dnsrecon.py

示例8: test_from_dnspython_zone

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def test_from_dnspython_zone(self):
        zone_file = self.get_zonefile_fixture()

        dnspython_zone = dnszone.from_text(
            zone_file,
            relativize=False,
            check_origin=False
        )

        zone = dnsutils.from_dnspython_zone(dnspython_zone)

        self.assertIsInstance(zone, objects.zone.Zone) 
开发者ID:openstack,项目名称:designate,代码行数:14,代码来源:test_dnsutils.py

示例9: test_parse_zone

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def test_parse_zone(self):
        zone_file = self.get_zonefile_fixture()

        dnspython_zone = dnszone.from_text(
            zone_file,
            # Don't relativize, otherwise we end up with '@' record names.
            relativize=False,
            # Dont check origin, we allow missing NS records (missing SOA
            # records are taken care of in _create_zone).
            check_origin=False
        )

        zone = dnsutils.from_dnspython_zone(dnspython_zone)

        for rrset in zone.recordsets:
            k = (rrset.name, rrset.type)
            self.assertIn(k, SAMPLES)

            sample_ttl = SAMPLES[k].get('ttl', None)
            if rrset.obj_attr_is_set('ttl') or sample_ttl is not None:
                self.assertEqual(sample_ttl, rrset.ttl)

            self.assertEqual(len(rrset.records), len(SAMPLES[k]['records']))

            for record in rrset.records:
                self.assertIn(record.data, SAMPLES[k]['records'])

        self.assertEqual(len(SAMPLES), len(zone.recordsets))
        self.assertEqual('example.com.', zone.name) 
开发者ID:openstack,项目名称:designate,代码行数:31,代码来源:test_dnsutils.py

示例10: release

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def release(self, zone):
        # Release the lock
        with self.lock:
            try:
                self.data.pop(zone)
            except KeyError:
                pass 
开发者ID:openstack,项目名称:designate,代码行数:9,代码来源:dnsutils.py

示例11: from_dnspython_zone

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def from_dnspython_zone(dnspython_zone):
    # dnspython never builds a zone with more than one SOA, even if we give
    # it a zonefile that contains more than one
    soa = dnspython_zone.get_rdataset(dnspython_zone.origin, 'SOA')
    if soa is None:
        raise exceptions.BadRequest('An SOA record is required')
    if soa.ttl == 0:
        soa.ttl = CONF['service:central'].min_ttl
    email = soa[0].rname.to_text(omit_final_dot=True)
    if six.PY3 and isinstance(email, bytes):
        email = email.decode('utf-8')
    email = email.replace('.', '@', 1)

    name = dnspython_zone.origin.to_text()
    if six.PY3 and isinstance(name, bytes):
        name = name.decode('utf-8')

    values = {
        'name': name,
        'email': email,
        'ttl': soa.ttl,
        'serial': soa[0].serial,
        'retry': soa[0].retry,
        'expire': soa[0].expire
    }

    zone = objects.Zone(**values)

    rrsets = dnspyrecords_to_recordsetlist(dnspython_zone.nodes)
    zone.recordsets = rrsets
    return zone 
开发者ID:openstack,项目名称:designate,代码行数:33,代码来源:dnsutils.py

示例12: axfr

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def axfr(self, server):
        """
        Perform domain transfer

        :param server: domain server
        """
        logger.log('DEBUG', f'Trying to perform domain transfer in {server} of {self.domain}')
        try:
            xfr = dns.query.xfr(where=server, zone=self.domain,
                                timeout=5.0, lifetime=10.0)
            zone = dns.zone.from_xfr(xfr)
        except Exception as e:
            logger.log('DEBUG', e.args)
            logger.log('DEBUG', f'Domain transfer to server {server} of {self.domain} failed')
            return
        names = zone.nodes.keys()
        for name in names:
            full_domain = str(name) + '.' + self.domain
            subdomain = self.match_subdomains(self.domain, full_domain)
            self.subdomains = self.subdomains.union(subdomain)
            record = zone[name].to_text(name)
            self.results.append(record)
        if self.results:
            logger.log('DEBUG', f'Found the domain transfer record of {self.domain} on {server}')
            logger.log('DEBUG', '\n'.join(self.results))
            self.results = [] 
开发者ID:shmilylty,项目名称:OneForAll,代码行数:28,代码来源:axfr.py

示例13: checkaxfr

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def checkaxfr(domain):
  domain = domain.strip()
  try:
    ns_query = dns.resolver.query(domain,'NS')
    for ns in ns_query.rrset:
      nameserver = str(ns)[:-1]
      if nameserver is None or nameserver == "":
        continue

      try:
        axfr = dns.query.xfr(nameserver, domain, lifetime=5)
        try:
          zone = dns.zone.from_xfr(axfr)
          if zone is None:
            continue
          LOGFILE.write("Success: " + domain + " @ " + nameserver + "\n")
          LOGFILE.flush()
          OUTPUTFILE.write("Success: " + domain + " @ " + nameserver + "\n")
          OUTPUTFILE.flush()
          for name, node in zone.nodes.items():
            rdatasets = node.rdatasets
            for rdataset in rdatasets:
              OUTPUTFILE.write(str(name) + " " + str(rdataset) + "\n")
              OUTPUTFILE.flush()
        except Exception as e:
          continue
      except Exception as e:
        continue
  except Exception as e:
    pass
  LOGFILE.write("Finished: " + domain + "\n")
  LOGFILE.flush() 
开发者ID:internetwache,项目名称:Python-AXFR-Test,代码行数:34,代码来源:axfr-test.py

示例14: main

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def main(address):
    soa_answer = dns.resolver.query(address, 'SOA')
    master_answer = dns.resolver.query(soa_answer[0].mname, 'A')
    try:
        z = dns.zone.from_xfr(dns.query.xfr(master_answer[0].address, address))
        names = z.nodes.keys()
        names.sort()
        for n in names:
            print(z[n].to_text(n))
    except socket.error as e:
        print('Failed to perform zone transfer:', e)
    except dns.exception.FormError as e:
        print('Failed to perform zone transfer:', e) 
开发者ID:PacktPublishing,项目名称:Python-Network-Programming-Cookbook-Second-Edition,代码行数:15,代码来源:11_4_dns_zone_transfer.py

示例15: GetZone

# 需要导入模块: import dns [as 别名]
# 或者: from dns import zone [as 别名]
def GetZone(self, zone):
    xfr = dns.query.xfr(self.server.settings['host'], zone, timeout=self.server.settings.get('timeout', 1.)*10., port=self.server.settings['port'], keyring=self.GetKeyring())
    zoneObj = dns.zone.from_xfr(xfr)
    return zoneObj 
开发者ID:andreas-p,项目名称:admin4,代码行数:6,代码来源:_dns.py


注:本文中的dns.zone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。