]> git.saurik.com Git - apple/network_cmds.git/blame - unbound/libunbound/python/doc/examples/example1a.rst
network_cmds-596.100.2.tar.gz
[apple/network_cmds.git] / unbound / libunbound / python / doc / examples / example1a.rst
CommitLineData
89c4ed63
A
1.. _example_resolve_name:
2
3==============================
4Resolve a name
5==============================
6
7This 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
23In contrast with C API, the source code is more compact while the performance of C implementation is preserved.
24The 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
26If only domain name is given, the :meth:`unbound.ub_ctx.resolve` looks for A records in IN class.