Doing a DNS resolve on a unicode-hostname return the following:
'\195\164\195\182\195\188o.mydomain104.local.'
The \195\164
is actually the following unicode letter: Ä
(u'\xc4'
).
The original hostname is:
ÄÖÜO.mydomain104.local
I'm looking for a way to convert it back to the unicode string (in python2.7)
In case the original code is needed, it's something like the following:
from dns import resolver, reversename
from dns.exception import DNSException
def get_name(ip_address):
answer = None
res = resolver.Resolver()
addr = reversename.from_address(ip_address)
try:
answer = res.query(addr, "PTR")[0].to_text().decode("utf-8")
except DNSException:
pass
return answer
I was looking at both
.encode
and.decode
, theunicodedata
lib andcodecs
and found nothing that worked.