ns-lookup.py revision 291767
1184054Slulf#!/usr/bin/python
2186743Slulf# vim:fileencoding=utf-8
3184054Slulf'''
4184054Slulf ns-lookup.py: Example shows how to lookup for NS records
5184054Slulf
6184054Slulf Authors: Zdenek Vasicek (vasicek AT fit.vutbr.cz)
7184054Slulf          Marek Vavrusa  (xvavru00 AT stud.fit.vutbr.cz)
8184054Slulf
9184054Slulf Copyright (c) 2008. All rights reserved.
10184054Slulf
11184054Slulf This software is open source.
12184054Slulf
13184054Slulf Redistribution and use in source and binary forms, with or without
14184054Slulf modification, are permitted provided that the following conditions
15184054Slulf are met:
16184054Slulf
17184054Slulf Redistributions of source code must retain the above copyright notice,
18184054Slulf this list of conditions and the following disclaimer.
19184054Slulf
20184054Slulf Redistributions in binary form must reproduce the above copyright notice,
21184054Slulf this list of conditions and the following disclaimer in the documentation
22184054Slulf and/or other materials provided with the distribution.
23184054Slulf
24184054Slulf THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25184054Slulf "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26184054Slulf TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27184054Slulf PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
28184054Slulf LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29184054Slulf CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30184054Slulf SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31184054Slulf INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32184054Slulf CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33184054Slulf ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34185134Slulf POSSIBILITY OF SUCH DAMAGE.
35184054Slulf'''
36184054Slulffrom __future__ import print_function
37184054Slulfimport unbound
38184054Slulf
39184054Slulfctx = unbound.ub_ctx()
40184054Slulfctx.resolvconf("/etc/resolv.conf")
41184054Slulf
42184054Slulfstatus, result = ctx.resolve("vutbr.cz", unbound.RR_TYPE_NS, unbound.RR_CLASS_IN)
43184054Slulfif status == 0 and result.havedata:
44184054Slulf    print("Result:")
45184054Slulf    print("      raw data:", result.data)
46184054Slulf    for k in sorted(result.data.domain_list):
47184054Slulf        print("      host: %s" % k)
48184054Slulf
49184054Slulf