1238106Sdes#!/usr/bin/python
2238106Sdes'''
3238106Sdes dns-lookup.py : This example shows how to resolve IP address
4238106Sdes
5238106Sdes Authors: Zdenek Vasicek (vasicek AT fit.vutbr.cz)
6238106Sdes          Marek Vavrusa  (xvavru00 AT stud.fit.vutbr.cz)
7238106Sdes
8238106Sdes Copyright (c) 2008. All rights reserved.
9238106Sdes
10238106Sdes This software is open source.
11238106Sdes
12238106Sdes Redistribution and use in source and binary forms, with or without
13238106Sdes modification, are permitted provided that the following conditions
14238106Sdes are met:
15238106Sdes
16238106Sdes Redistributions of source code must retain the above copyright notice,
17238106Sdes this list of conditions and the following disclaimer.
18238106Sdes
19238106Sdes Redistributions in binary form must reproduce the above copyright notice,
20238106Sdes this list of conditions and the following disclaimer in the documentation
21238106Sdes and/or other materials provided with the distribution.
22238106Sdes
23238106Sdes THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24238106Sdes "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25238106Sdes TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26238106Sdes PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27238106Sdes LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28238106Sdes CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29238106Sdes SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30238106Sdes INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31238106Sdes CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32238106Sdes ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33238106Sdes POSSIBILITY OF SUCH DAMAGE.
34238106Sdes'''
35291767Sdesfrom __future__ import print_function
36238106Sdesimport unbound
37238106Sdes
38238106Sdesctx = unbound.ub_ctx()
39238106Sdesctx.resolvconf("/etc/resolv.conf")
40238106Sdes
41238106Sdesstatus, result = ctx.resolve("www.nic.cz", unbound.RR_TYPE_A, unbound.RR_CLASS_IN)
42238106Sdesif status == 0 and result.havedata:
43291767Sdes    print("Result:", sorted(result.data.address_list))
44238106Sdeselif status != 0:
45285206Sdes    print("Error:", unbound.ub_strerror(status))
46