Source code for asyncdnspy.dns_message_resourcerecord

#!/usr/bin/env python

import ipaddress

from asyncdnspy.dnspy_enum import RecordType
from typing import List


[docs]class ResourceRecord(object): """Class that holds resource record details.""" __name = '' __record_type = 0 __class_type = 0 __ttl = 0 __record_data_length = 0 __record_data = [] @property def name(self): """Name property of dns message question.""" return self.__name @name.setter def name(self, value: str): """Setter function of name property. :param value: Value of name. :type value: str. """ self.__name = value @property def record_type(self): """Record type property of dns message question.""" return self.__record_type @record_type.setter def record_type(self, value: int): """Setter function of record type property. :param value: Value of record type. :type value: 16 bit integer. """ self.__record_type = value @property def class_type(self): """Class type property of dns message question.""" return self.__class_type @class_type.setter def class_type(self, value: int): """Setter function of class type property. :param value: Value of class type. :type value: 16 bit integer. """ self.__class_type = value @property def ttl(self): """Time to live property of dns message question.""" return self.__ttl @ttl.setter def ttl(self, value: int): """Setter function of ttl property. :param value: Value of ttl. :type value: 32 bit unsigned integer. """ self.__ttl = value @property def record_data_length(self): """Length of record data property of dns message question.""" return self.__record_data_length @record_data_length.setter def record_data_length(self, value: int): """Setter function of record type property. :param value: Value of record type. :type value: 16 bit unsigned integer. """ self.__record_data_length = value @property def record_data(self): """Record data property of dns message question.""" return self.__record_data @record_data.setter def record_data(self, value: List): """Setter function of record data property. :param value: Value of record data. :type value: byte list. """ self.__record_data = value
[docs] def get_ipv4_address(self): """Returns ipv4 address if record type A. :type value: IPv4Address. """ if self.record_type == RecordType.a.value: return ipaddress.IPv4Address(bytes(self.record_data)) return None
[docs] def get_ipv6_address(self): """Returns ipv6 address if record type AAAA. :type value: IPv6Address. """ if self.record_type == RecordType.aaaa.value: return ipaddress.IPv6Address(bytes(self.record_data)) return None
[docs] def get_txt(self): """Returns readable TXT if record type TXT. :type value: str. """ if self.record_type == RecordType.txt.value: return bytes(self.record_data).decode('utf-8') return None