]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/unbound/libunbound/python/doc/examples/example1b.rst
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / unbound / libunbound / python / doc / examples / example1b.rst
1 .. _example_reverse_lookup:
2
3 ==============================
4 Reverse DNS lookup
5 ==============================
6
7 Reverse DNS lookup involves determining the hostname associated with a given IP address.
8 This example shows how reverse lookup can be done using unbound module.
9
10 For the reverse DNS records, the special domain in-addr.arpa is reserved. 
11 For example, a host name for the IP address 74.125.43.147 can be obtained by issuing a DNS query for the PTR record for address 147.43.125.74.in-addr.arpa.
12
13 ::
14
15         #!/usr/bin/python
16         import unbound
17         
18         ctx = unbound.ub_ctx()
19         ctx.resolvconf("/etc/resolv.conf")
20         
21         status, result = ctx.resolve(unbound.reverse("74.125.43.147") + ".in-addr.arpa.", unbound.RR_TYPE_PTR, unbound.RR_CLASS_IN)
22         if status == 0 and result.havedata:
23                 print "Result.data:", result.data.domain_list
24         elif status != 0:
25                 print "Resolve error:", unbound.ub_strerror(status)
26
27 In order to simplify the python code, unbound module contains function which reverses the hostname components. 
28 This function is defined as follows::
29
30         def reverse(domain):
31                 return '.'.join([a for a in domain.split(".")][::-1])
32
33