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