示例#1
0
    def get_nsec(self, domain: str, as_json: bool = False):
        """Accepts a domain: str. Returns a formatted answer dictionary with the nsec records inside the 'answer'."""
        formatted_answer = {
            'domain': domain,
            'rr_types': ["nsec"],
            'answer': None
        }

        status, result = Resolver.ctx_dnssec.resolve(domain,
                                                     rrtype=ub.RR_TYPE_NSEC)
        if status == 0 and result.havedata:
            nsec_list = result.data.data
            formatted_answer['answer'] = {}
            i = 0
            for nsec in nsec_list:
                if as_json:
                    formatted_answer['answer'][i] = str(nsec)
                else:
                    formatted_answer['answer'][i] = nsec
                i += 1
        elif status != 0:  # throw/raise error
            print("Resolve error: ", ub.ub_strerror(status), result.rcode_str)
        elif result.havedata == 0:  # if no data in result
            print("No data", result.rcode_str)

        if as_json:
            return json.dumps(formatted_answer)
        return DNSFormattedResponse(formatted_answer)
示例#2
0
    def get_rrsigs(self, domain: str, as_json: bool = False):
        """Accepts a domain: str. Returns a formatted answer dictionary, with rrsig records in the 'answer'."""
        formatted_answer = {
            'domain': domain,
            'rr_types': ["rrsig"],
            'answer': None
        }

        status, result = Resolver.ctx_dnssec.resolve(domain,
                                                     rrtype=ub.RR_TYPE_RRSIG)
        if status == 0 and result.havedata:
            print("rrsigs returned.")
            rrsig_list = result.data.data
            formatted_answer['answer'] = {}
            i = 0
            for sig in rrsig_list:
                if as_json:
                    formatted_answer['answer'][i] = str(sig)
                else:
                    formatted_answer['answer'][i] = sig
                i += 1
        elif status != 0:  # throw/raise error
            print("Resolve error: ", ub.ub_strerror(status))
        elif result.havedata == 0:  # if no data in result
            print("No data.")
            print(result.rcode_str)
        elif result.rcode != 0:
            print(result.rcode_str)

        if as_json:
            return json.dumps(formatted_answer)
        return DNSFormattedResponse(formatted_answer)
示例#3
0
    def get_ds(self, domain: str, as_json: bool = False):
        """Accepts a domain. Returns a formatted answer dictionary with ds records in the 'answer'."""
        formatted_answer = {
            'domain': domain,
            'rr_types': ["ds"],
            'answer': None
        }

        status, result = Resolver.ctx_dnssec.resolve(domain,
                                                     rrtype=ub.RR_TYPE_DS)

        if status == 0 and result.havedata:
            print("ds record returned.")
            formatted_answer['answer'] = {}
            ds_records_list = result.data.data
            i = 0
            for ds in ds_records_list:
                if as_json:
                    formatted_answer['answer'][i] = str(ds)
                else:
                    formatted_answer['answer'][i] = ds
                i += 0
        elif status != 0:  # throw/raise error
            print("Resolve error: ", ub.ub_strerror(status))
        elif result.havedata == 0:  # if no data in result
            print("No data.")
        if as_json:
            return json.dumps(formatted_answer)
        return DNSFormattedResponse(formatted_answer)
示例#4
0
    def get_dnskeys(self, domain: str, as_json: bool = False):
        """Accepts a domain: str. Returns a formatted answer dictionary, including dnskey records in the 'answer'."""
        formatted_answer = {
            'domain': domain,
            'rr_types': ["dnskey"],
            'answer': None
        }

        status, result = Resolver.ctx_dnssec.resolve(domain,
                                                     rrtype=ub.RR_TYPE_DNSKEY)

        if status == 0 and result.havedata == 1:
            print("returned dnskeys.")
            formatted_answer['answer'] = {}
            dns_keys_list = result.data.data  # list of dnskeys. *should* return None or non-empty list
            i = 0
            for key in dns_keys_list:  # place into dict
                if as_json:
                    formatted_answer['answer'][i] = str(key)
                else:
                    formatted_answer['answer'][i] = key
                i += 1
        elif status != 0:  # throw/raise error
            print("Resolve error: ", ub.ub_strerror(status))
        elif result.havedata == 0:  # if no data in result
            print("No data.")

        if as_json:
            return json.dumps(formatted_answer)
        return DNSFormattedResponse(formatted_answer)
示例#5
0
    def get_soa(self, domain: str, as_json: bool = False):
        """
        Accepts domain: str. Returns a formatted answer containing 'Start Of Authority' records in the format:
        {'domain': 'example.com', 'rr_types':['soa'], 'answer': ['administrator info, other info, time info, etc]}.
        If no record is found, returns None in the answer section.
        Set 'as_json=True' to return a pure json response instead of the wrapped formatted response.
        """
        formatted_answer = {
            'domain': domain,
            'rr_types': ["soa"],
            'answer': None
        }

        soa_list = None
        status, result = Resolver.ctx_dnssec.resolve(domain, ub.RR_TYPE_SOA,
                                                     ub.RR_CLASS_IN)
        if status == 0 and result.havedata and result.secure == 1:
            formatted_answer['answer'] = {}
            soa_list = result.data.data
            i = 0
            for record in soa_list:
                formatted_answer['answer'][i] = str(record)
                i += 1
        elif status != 0:  # throw/raise error
            print("Resolve error: ", ub.ub_strerror(status))
        elif result.havedata == 0:  # if no data in result
            print("No data.")

        if as_json:
            return json.dumps(formatted_answer)
        return DNSFormattedResponse(formatted_answer)
示例#6
0
	def fetch(self):
		"""Generic fetching of record that are not of special form like
		SRV and TLSA.
		
		@returns: result part from (status, result) tupe of ub_ctx.resolve() or None on permanent SERVFAIL
		@throws: DnsError if unbound reports error
		"""
		for i in range(self.opts.attempts):
			(status, result) = self.resolver.resolve(self.domain, self.rrType, self.rrClass)
			
			if status != 0:
				raise DnsError("Resolving %s for %s: %s" % \
					(self.__class__.__name__, self.domain, ub_strerror(status)))
			
			if result.rcode != RCODE_SERVFAIL:
				logging.debug("Domain %s type %s: havedata %s, rcode %s", \
					self.domain, self.__class__.__name__, result.havedata, result.rcode_str)
				return result
			
		logging.info("Permanent SERVFAIL: domain %s type %s", \
			self.domain, self.__class__.__name__)
		return None
示例#7
0
#!/usr/bin/python
from unbound import ub_ctx,ub_strerror,RR_TYPE_A,RR_CLASS_IN

ctx = ub_ctx()
ctx.resolvconf("/etc/resolv.conf")
	
status, result = ctx.resolve("test.record.xxx", RR_TYPE_A, RR_CLASS_IN)
if status == 0 and result.havedata:
    print "Result:", result.data.address_list
else:
    print "No record found"

#define new local zone
status = ctx.zone_add("xxx.","static")
if (status != 0): print "Error zone_add:",status, ub_strerror(status)

#add RR to the zone
status = ctx.data_add("test.record.xxx. IN A 1.2.3.4")
if (status != 0): print "Error data_add:",status, ub_strerror(status)

#lookup for an A record
status, result = ctx.resolve("test.record.xxx", RR_TYPE_A, RR_CLASS_IN)
if status == 0 and result.havedata:
    print "Result:", result.data.as_address_list()
else:
    print "No record found"

示例#8
0
 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.
"""
import unbound
import time

ctx = unbound.ub_ctx()
ctx.resolvconf("/etc/resolv.conf")


def call_back(my_data, status, result):
    print "Call_back:", my_data
    if status == 0 and result.havedata:
        print "Result:", result.data.address_list
        my_data["done_flag"] = True


my_data = {"done_flag": False, "arbitrary": "object"}
status, async_id = ctx.resolve_async("www.nic.cz", my_data, call_back, unbound.RR_TYPE_A, unbound.RR_CLASS_IN)

while (status == 0) and (not my_data["done_flag"]):
    status = ctx.process()
    time.sleep(0.1)

if status != 0:
    print "Resolve error:", unbound.ub_strerror(status)
示例#9
0
 Redistributions of source code must retain the above copyright notice,
 this list of conditions and the following disclaimer.
 
 Redistributions in binary form must reproduce the above copyright notice,
 this list of conditions and the following disclaimer in the documentation
 and/or other materials provided with the distribution.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.
'''
import unbound

ctx = unbound.ub_ctx()
ctx.resolvconf("/etc/resolv.conf")

status, result = ctx.resolve("www.nic.cz", unbound.RR_TYPE_A,
                             unbound.RR_CLASS_IN)
if status == 0 and result.havedata:
    print("Result:", result.data.address_list)
elif status != 0:
    print("Error:", unbound.ub_strerror(status))
示例#10
0
import os
import unbound
from unbound import ub_ctx,RR_TYPE_A,RR_CLASS_IN

ctx = ub_ctx()
ctx.set_option("module-config:","iterator")
ctx.resolvconf("/etc/resolv.conf")

domain = input('Please provide a domain to search: ')
status, result = ctx.resolve(domain, RR_TYPE_A, RR_CLASS_IN)
if status == 0 and result.havedata:
    List = result.data.address_list
    results = " ".join(str(x) for x in List)
    print( results)
    status, result = ctx.resolve(unbound.reverse(results) + ".in-addr.arpa.", unbound.RR_TYPE_PTR, unbound.RR_CLASS_IN)
    if status == 0 and result.havedata:
        NL = result.data.domain_list
        reverse = " ".join(str(x) for x in NL)
        print(  reverse)
    elif status != 0:
        print( "Resolve error:", unbound.ub_strerror(status))
示例#11
0
#!/usr/bin/python
from unbound import ub_ctx, ub_strerror, RR_TYPE_A, RR_CLASS_IN

ctx = ub_ctx()
ctx.resolvconf("/etc/resolv.conf")

status, result = ctx.resolve("test.record.xxx", RR_TYPE_A, RR_CLASS_IN)
if status == 0 and result.havedata:
    print "Result:", result.data.address_list
else:
    print "No record found"

#define new local zone
status = ctx.zone_add("xxx.", "static")
if (status != 0): print "Error zone_add:", status, ub_strerror(status)

#add RR to the zone
status = ctx.data_add("test.record.xxx. IN A 1.2.3.4")
if (status != 0): print "Error data_add:", status, ub_strerror(status)

#lookup for an A record
status, result = ctx.resolve("test.record.xxx", RR_TYPE_A, RR_CLASS_IN)
if status == 0 and result.havedata:
    print "Result:", result.data.as_address_list()
else:
    print "No record found"
示例#12
0
 
 Redistributions of source code must retain the above copyright notice,
 this list of conditions and the following disclaimer.
 
 Redistributions in binary form must reproduce the above copyright notice,
 this list of conditions and the following disclaimer in the documentation
 and/or other materials provided with the distribution.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.
'''
import unbound

ctx = unbound.ub_ctx()
ctx.resolvconf("/etc/resolv.conf")

status, result = ctx.resolve("www.nic.cz", unbound.RR_TYPE_A, unbound.RR_CLASS_IN)
if status == 0 and result.havedata:
    print("Result:", result.data.address_list)
elif status != 0:
    print("Error:", unbound.ub_strerror(status))