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