idn-lookup.py revision 285206
1258945Sroberto#!/usr/bin/python 2258945Sroberto# vim:fileencoding=utf-8 3258945Sroberto''' 4258945Sroberto idn-lookup.py: IDN (Internationalized Domain Name) lookup support 5258945Sroberto 6258945Sroberto Authors: Zdenek Vasicek (vasicek AT fit.vutbr.cz) 7258945Sroberto Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz) 8258945Sroberto 9258945Sroberto Copyright (c) 2008. All rights reserved. 10258945Sroberto 11258945Sroberto This software is open source. 12258945Sroberto 13258945Sroberto Redistribution and use in source and binary forms, with or without 14280849Scy modification, are permitted provided that the following conditions 15280849Scy are met: 16258945Sroberto 17258945Sroberto Redistributions of source code must retain the above copyright notice, 18258945Sroberto this list of conditions and the following disclaimer. 19258945Sroberto 20258945Sroberto Redistributions in binary form must reproduce the above copyright notice, 21258945Sroberto this list of conditions and the following disclaimer in the documentation 22258945Sroberto and/or other materials provided with the distribution. 23258945Sroberto 24258945Sroberto THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25258945Sroberto "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26258945Sroberto TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27258945Sroberto PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 28258945Sroberto LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29258945Sroberto CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30258945Sroberto SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31258945Sroberto INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32258945Sroberto CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33258945Sroberto ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34258945Sroberto POSSIBILITY OF SUCH DAMAGE. 35258945Sroberto''' 36258945Srobertoimport unbound 37258945Srobertoimport locale 38258945Sroberto 39258945Srobertoctx = unbound.ub_ctx() 40258945Srobertoctx.set_option("module-config:","iterator") #We don't need validation 41258945Srobertoctx.resolvconf("/etc/resolv.conf") 42258945Sroberto 43258945Sroberto#The unicode IDN string is automatically converted (if necessary) 44258945Srobertostatus, result = ctx.resolve(u"www.h����ky����rky.cz", unbound.RR_TYPE_A, unbound.RR_CLASS_IN) 45258945Srobertoif status == 0 and result.havedata: 46258945Sroberto print("Result:") 47258945Sroberto print(" raw data:", result.data) 48258945Sroberto for k in result.data.address_list: 49258945Sroberto print(" address:%s" % k) 50258945Sroberto 51258945Srobertostatus, result = ctx.resolve(u"h����ky����rky.cz", unbound.RR_TYPE_MX, unbound.RR_CLASS_IN) 52258945Srobertoif status == 0 and result.havedata: 53258945Sroberto print("Result:") 54258945Sroberto print(" raw data:", result.data) 55258945Sroberto for k in result.data.mx_list_idn: 56258945Sroberto print(" priority:%d address:%s" % k) 57258945Sroberto 58258945Srobertostatus, result = ctx.resolve(unbound.reverse('217.31.204.66')+'.in-addr.arpa', unbound.RR_TYPE_PTR, unbound.RR_CLASS_IN) 59258945Srobertoif status == 0 and result.havedata: 60258945Sroberto print("Result.data:", result.data) 61258945Sroberto for k in result.data.domain_list_idn: 62258945Sroberto print(" dname:%s" % k) 63258945Sroberto