]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - libunbound/python/doc/examples/example1a.rst
import unbound 1.6.0
[FreeBSD/FreeBSD.git] / libunbound / python / doc / examples / example1a.rst
1 .. _example_resolve_name:
2
3 Resolve a name
4 ==============
5
6 This basic example shows how to create a context and resolve a host address
7 (DNS record of A type).
8
9 Source code
10 -----------
11
12 ::
13
14     #!/usr/bin/python
15     import unbound
16
17     ctx = unbound.ub_ctx()
18     ctx.resolvconf("/etc/resolv.conf")
19
20     status, result = ctx.resolve("www.google.com")
21     if status == 0 and result.havedata:
22         print "Result.data:", result.data.address_list
23     elif status != 0:
24         print "Resolve error:", unbound.ub_strerror(status)
25
26 In contrast with the C API, the source code is more compact while the
27 performance of C implementation is preserved. 
28 The main advantage is that you need not take care about the deallocation and
29 allocation of context and result structures; pyUnbound module does it
30 automatically for you. 
31
32 If only domain name is given, the :meth:`unbound.ub_ctx.resolve` looks for
33 A records in IN class.