xref: /netbsd-src/external/bsd/unbound/dist/libunbound/python/doc/examples/example1a.rst (revision 0cd9f4ecf44538bbdd5619b5b2081449960ab3e6)
1.. _example_resolve_name:
2
3Resolve a name
4==============
5
6This basic example shows how to create a context and resolve a host address
7(DNS record of A type).
8
9Source 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
26In contrast with the C API, the source code is more compact while the
27performance of C implementation is preserved.
28The main advantage is that you need not take care about the deallocation and
29allocation of context and result structures; pyUnbound module does it
30automatically for you.
31
32If only domain name is given, the :meth:`unbound.ub_ctx.resolve` looks for
33A records in IN class.
34