reverse-lookup.py revision 1.1.1.1.2.2 1 1.1.1.1.2.2 pgoyette #!/usr/bin/python
2 1.1.1.1.2.2 pgoyette '''
3 1.1.1.1.2.2 pgoyette reverse-lookup.py: Example shows how to resolve reverse record
4 1.1.1.1.2.2 pgoyette
5 1.1.1.1.2.2 pgoyette Authors: Zdenek Vasicek (vasicek AT fit.vutbr.cz)
6 1.1.1.1.2.2 pgoyette Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz)
7 1.1.1.1.2.2 pgoyette
8 1.1.1.1.2.2 pgoyette Copyright (c) 2008. All rights reserved.
9 1.1.1.1.2.2 pgoyette
10 1.1.1.1.2.2 pgoyette This software is open source.
11 1.1.1.1.2.2 pgoyette
12 1.1.1.1.2.2 pgoyette Redistribution and use in source and binary forms, with or without
13 1.1.1.1.2.2 pgoyette modification, are permitted provided that the following conditions
14 1.1.1.1.2.2 pgoyette are met:
15 1.1.1.1.2.2 pgoyette
16 1.1.1.1.2.2 pgoyette Redistributions of source code must retain the above copyright notice,
17 1.1.1.1.2.2 pgoyette this list of conditions and the following disclaimer.
18 1.1.1.1.2.2 pgoyette
19 1.1.1.1.2.2 pgoyette Redistributions in binary form must reproduce the above copyright notice,
20 1.1.1.1.2.2 pgoyette this list of conditions and the following disclaimer in the documentation
21 1.1.1.1.2.2 pgoyette and/or other materials provided with the distribution.
22 1.1.1.1.2.2 pgoyette
23 1.1.1.1.2.2 pgoyette THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 1.1.1.1.2.2 pgoyette "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1.1.1.2.2 pgoyette TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1.1.1.2.2 pgoyette PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27 1.1.1.1.2.2 pgoyette LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1.1.1.2.2 pgoyette CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1.1.1.2.2 pgoyette SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1.1.1.2.2 pgoyette INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1.1.1.2.2 pgoyette CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1.1.1.2.2 pgoyette ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1.1.1.2.2 pgoyette POSSIBILITY OF SUCH DAMAGE.
34 1.1.1.1.2.2 pgoyette '''
35 1.1.1.1.2.2 pgoyette from __future__ import print_function
36 1.1.1.1.2.2 pgoyette import unbound
37 1.1.1.1.2.2 pgoyette
38 1.1.1.1.2.2 pgoyette ctx = unbound.ub_ctx()
39 1.1.1.1.2.2 pgoyette ctx.resolvconf("/etc/resolv.conf")
40 1.1.1.1.2.2 pgoyette
41 1.1.1.1.2.2 pgoyette status, result = ctx.resolve(unbound.reverse("74.125.43.147") + ".in-addr.arpa.", unbound.RR_TYPE_PTR, unbound.RR_CLASS_IN)
42 1.1.1.1.2.2 pgoyette if status == 0 and result.havedata:
43 1.1.1.1.2.2 pgoyette print("Result.data:", result.data, sorted(result.data.domain_list))
44 1.1.1.1.2.2 pgoyette
45