]> git.saurik.com Git - apple/network_cmds.git/blob - unbound/libunbound/python/doc/examples/example1a.rst
3c81547f294874c24be9036f2fb33b858445da83
[apple/network_cmds.git] / 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.