def dnshostencode(data, zone):
"""
encodes the data in a DNS transmittable hostname, 0-9A-F
:param data: DNS transmittable hostname data
:param zone: DNS zone to add at the end
:return: encoded form
"""
# TODO: sending 0-9A-Z would be better
res = b""
sdata = base64.b16encode(data)
# every 60 characters, we will add a dot
for i in range(len(sdata)):
res += sdata[i:i+1]
if (i+1) % 60 == 0 and (i+1) < len(sdata):
res += b'.'
return res + b'.' + zone.encode('utf-8') + b'.'
评论列表
文章目录