1238106Sdes#!/usr/bin/python 2238106Sdes# vim:fileencoding=utf-8 3238106Sdes''' 4238106Sdes idn-lookup.py: IDN (Internationalized Domain Name) lookup support 5238106Sdes 6238106Sdes Authors: Zdenek Vasicek (vasicek AT fit.vutbr.cz) 7238106Sdes Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz) 8238106Sdes 9238106Sdes Copyright (c) 2008. All rights reserved. 10238106Sdes 11238106Sdes This software is open source. 12238106Sdes 13238106Sdes Redistribution and use in source and binary forms, with or without 14238106Sdes modification, are permitted provided that the following conditions 15238106Sdes are met: 16238106Sdes 17238106Sdes Redistributions of source code must retain the above copyright notice, 18238106Sdes this list of conditions and the following disclaimer. 19238106Sdes 20238106Sdes Redistributions in binary form must reproduce the above copyright notice, 21238106Sdes this list of conditions and the following disclaimer in the documentation 22238106Sdes and/or other materials provided with the distribution. 23238106Sdes 24238106Sdes THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25238106Sdes "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26238106Sdes TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27238106Sdes PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 28238106Sdes LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29238106Sdes CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30238106Sdes SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31238106Sdes INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32238106Sdes CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33238106Sdes ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34238106Sdes POSSIBILITY OF SUCH DAMAGE. 35238106Sdes''' 36291767Sdesfrom __future__ import print_function 37238106Sdesimport unbound 38238106Sdesimport locale 39238106Sdes 40238106Sdesctx = unbound.ub_ctx() 41238106Sdesctx.set_option("module-config:","iterator") #We don't need validation 42238106Sdesctx.resolvconf("/etc/resolv.conf") 43238106Sdes 44238106Sdes#The unicode IDN string is automatically converted (if necessary) 45238106Sdesstatus, result = ctx.resolve(u"www.h����ky����rky.cz", unbound.RR_TYPE_A, unbound.RR_CLASS_IN) 46238106Sdesif status == 0 and result.havedata: 47285206Sdes print("Result:") 48285206Sdes print(" raw data:", result.data) 49291767Sdes for k in sorted(result.data.address_list): 50285206Sdes print(" address:%s" % k) 51238106Sdes 52238106Sdesstatus, result = ctx.resolve(u"h����ky����rky.cz", unbound.RR_TYPE_MX, unbound.RR_CLASS_IN) 53238106Sdesif status == 0 and result.havedata: 54285206Sdes print("Result:") 55285206Sdes print(" raw data:", result.data) 56291767Sdes for k in sorted(result.data.mx_list_idn): 57285206Sdes print(" priority:%d address:%s" % k) 58238106Sdes 59238106Sdesstatus, result = ctx.resolve(unbound.reverse('217.31.204.66')+'.in-addr.arpa', unbound.RR_TYPE_PTR, unbound.RR_CLASS_IN) 60238106Sdesif status == 0 and result.havedata: 61285206Sdes print("Result.data:", result.data) 62291767Sdes for k in sorted(result.data.domain_list_idn): 63285206Sdes print(" dname:%s" % k) 64