15116SN/A#!/usr/bin/python
216387Sgoetz# vim:fileencoding=utf-8
35116SN/A'''
45116SN/A ns-lookup.py: Example shows how to lookup for NS records
55116SN/A
65116SN/A Authors: Zdenek Vasicek (vasicek AT fit.vutbr.cz)
75116SN/A          Marek Vavrusa  (xvavru00 AT stud.fit.vutbr.cz)
85116SN/A
95116SN/A Copyright (c) 2008. All rights reserved.
105116SN/A
115116SN/A This software is open source.
125116SN/A
135116SN/A Redistribution and use in source and binary forms, with or without
145116SN/A modification, are permitted provided that the following conditions
155116SN/A are met:
165116SN/A
175116SN/A Redistributions of source code must retain the above copyright notice,
185116SN/A this list of conditions and the following disclaimer.
195116SN/A
205116SN/A Redistributions in binary form must reproduce the above copyright notice,
215116SN/A this list of conditions and the following disclaimer in the documentation
225116SN/A and/or other materials provided with the distribution.
235116SN/A
245116SN/A THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
255116SN/A "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
265116SN/A TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
275116SN/A PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
285116SN/A LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
295116SN/A CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
305116SN/A SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
315116SN/A INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
325116SN/A CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
335116SN/A ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
345116SN/A POSSIBILITY OF SUCH DAMAGE.
355116SN/A'''
365116SN/Aimport unbound
375116SN/A
385116SN/Actx = unbound.ub_ctx()
395116SN/Actx.resolvconf("/etc/resolv.conf")
405116SN/A
415116SN/Astatus, result = ctx.resolve("vutbr.cz", unbound.RR_TYPE_NS, unbound.RR_CLASS_IN)
425116SN/Aif status == 0 and result.havedata:
435116SN/A    print("Result:")
445116SN/A    print("      raw data:", result.data)
455116SN/A    for k in result.data.domain_list:
465116SN/A        print("      host: %s" % k)
475116SN/A
485116SN/A