idn-lookup.py revision 291767
1#!/usr/bin/python
2# vim:fileencoding=utf-8
3'''
4 idn-lookup.py: IDN (Internationalized Domain Name) lookup support
5
6 Authors: Zdenek Vasicek (vasicek AT fit.vutbr.cz)
7          Marek Vavrusa  (xvavru00 AT stud.fit.vutbr.cz)
8
9 Copyright (c) 2008. All rights reserved.
10
11 This software is open source.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
15 are met:
16
17 Redistributions of source code must retain the above copyright notice,
18 this list of conditions and the following disclaimer.
19
20 Redistributions in binary form must reproduce the above copyright notice,
21 this list of conditions and the following disclaimer in the documentation
22 and/or other materials provided with the distribution.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35'''
36from __future__ import print_function
37import unbound
38import locale
39
40ctx = unbound.ub_ctx()
41ctx.set_option("module-config:","iterator") #We don't need validation
42ctx.resolvconf("/etc/resolv.conf")
43
44#The unicode IDN string is automatically converted (if necessary)
45status, result = ctx.resolve(u"www.h����ky����rky.cz", unbound.RR_TYPE_A, unbound.RR_CLASS_IN)
46if status == 0 and result.havedata:
47    print("Result:")
48    print("      raw data:", result.data)
49    for k in sorted(result.data.address_list):
50        print("      address:%s" % k)
51
52status, result = ctx.resolve(u"h����ky����rky.cz", unbound.RR_TYPE_MX, unbound.RR_CLASS_IN)
53if status == 0 and result.havedata:
54    print("Result:")
55    print("      raw data:", result.data)
56    for k in sorted(result.data.mx_list_idn):
57        print("      priority:%d address:%s" % k)
58
59status, result = ctx.resolve(unbound.reverse('217.31.204.66')+'.in-addr.arpa', unbound.RR_TYPE_PTR, unbound.RR_CLASS_IN)
60if status == 0 and result.havedata:
61    print("Result.data:", result.data)
62    for k in sorted(result.data.domain_list_idn):
63        print("      dname:%s" % k)
64