1*3b6c3722Schristos#!/usr/bin/python 2*3b6c3722Schristos# vim:fileencoding=utf-8 3*3b6c3722Schristos''' 4*3b6c3722Schristos example8-1.py: Example shows how to lookup for MX and NS records 5*3b6c3722Schristos 6*3b6c3722Schristos Authors: Zdenek Vasicek (vasicek AT fit.vutbr.cz) 7*3b6c3722Schristos Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz) 8*3b6c3722Schristos 9*3b6c3722Schristos Copyright (c) 2008. All rights reserved. 10*3b6c3722Schristos 11*3b6c3722Schristos This software is open source. 12*3b6c3722Schristos 13*3b6c3722Schristos Redistribution and use in source and binary forms, with or without 14*3b6c3722Schristos modification, are permitted provided that the following conditions 15*3b6c3722Schristos are met: 16*3b6c3722Schristos 17*3b6c3722Schristos Redistributions of source code must retain the above copyright notice, 18*3b6c3722Schristos this list of conditions and the following disclaimer. 19*3b6c3722Schristos 20*3b6c3722Schristos Redistributions in binary form must reproduce the above copyright notice, 21*3b6c3722Schristos this list of conditions and the following disclaimer in the documentation 22*3b6c3722Schristos and/or other materials provided with the distribution. 23*3b6c3722Schristos 24*3b6c3722Schristos THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25*3b6c3722Schristos "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26*3b6c3722Schristos TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27*3b6c3722Schristos PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 28*3b6c3722Schristos LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29*3b6c3722Schristos CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30*3b6c3722Schristos SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31*3b6c3722Schristos INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32*3b6c3722Schristos CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33*3b6c3722Schristos ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34*3b6c3722Schristos POSSIBILITY OF SUCH DAMAGE. 35*3b6c3722Schristos''' 36*3b6c3722Schristosfrom __future__ import print_function 37*3b6c3722Schristosimport unbound 38*3b6c3722Schristos 39*3b6c3722Schristosctx = unbound.ub_ctx() 40*3b6c3722Schristosctx.resolvconf("/etc/resolv.conf") 41*3b6c3722Schristos 42*3b6c3722Schristosstatus, result = ctx.resolve("nic.cz", unbound.RR_TYPE_MX, unbound.RR_CLASS_IN) 43*3b6c3722Schristosif status == 0 and result.havedata: 44*3b6c3722Schristos print("Result:") 45*3b6c3722Schristos print(" raw data:", result.data) 46*3b6c3722Schristos for k in sorted(result.data.mx_list): 47*3b6c3722Schristos print(" priority:%d address:%s" % k) 48*3b6c3722Schristos 49*3b6c3722Schristosstatus, result = ctx.resolve("nic.cz", unbound.RR_TYPE_A, unbound.RR_CLASS_IN) 50*3b6c3722Schristosif status == 0 and result.havedata: 51*3b6c3722Schristos print("Result:") 52*3b6c3722Schristos print(" raw data:", result.data) 53*3b6c3722Schristos for k in sorted(result.data.address_list): 54*3b6c3722Schristos print(" address:%s" % k) 55*3b6c3722Schristos 56*3b6c3722Schristosstatus, result = ctx.resolve("nic.cz", unbound.RR_TYPE_NS, unbound.RR_CLASS_IN) 57*3b6c3722Schristosif status == 0 and result.havedata: 58*3b6c3722Schristos print("Result:") 59*3b6c3722Schristos print(" raw data:", result.data) 60*3b6c3722Schristos for k in sorted(result.data.domain_list): 61*3b6c3722Schristos print(" host: %s" % k) 62*3b6c3722Schristos 63