Internationalized domain name support

Unlike the libUnbound, pyUnbound is able to handle IDN queries.

Automatic IDN DNAME conversion

If we use unicode string in unbound.ub_ctx.resolve() method, the IDN DNAME conversion (if it is necessary) is performed on background.

Source code

#!/usr/bin/python
# vim:fileencoding=utf-8
#
# IDN (Internationalized Domain Name) lookup support
#
import unbound

ctx = unbound.ub_ctx()
ctx.resolvconf("/etc/resolv.conf")

status, result = ctx.resolve(u"www.háčkyčárky.cz", unbound.RR_TYPE_A, unbound.RR_CLASS_IN)
if status == 0 and result.havedata:
    print "Result:"
    print "      raw data:", result.data
    for k in result.data.address_list:
        print "      address:%s" % k

IDN converted attributes

The unbound.ub_data class contains attributes suffix which converts the dname to UTF string. These attributes have the _idn suffix.

Apart from this approach, two conversion functions exist (unbound.idn2dname() and unbound.dname2idn()).

Source code

#!/usr/bin/python
# vim:fileencoding=utf-8
#
# IDN (Internationalized Domain Name) lookup support (lookup for MX)
#
import unbound

ctx = unbound.ub_ctx()
ctx.resolvconf("/etc/resolv.conf")

status, result = ctx.resolve(u"háčkyčárky.cz", unbound.RR_TYPE_MX, unbound.RR_CLASS_IN)
if status == 0 and result.havedata:
    print "Result:"
    print "      raw data:", result.data
    for k in result.data.mx_list_idn:
        print "      priority:%d address:%s" % k