Encoding/Decoding AD dnsRecord values with Python



I am attempting to edit Active Directory dnsRecord values via Python. The attribute values are a binary struct - I find documentation for the struct in various places such as I also found a few examples of Perl code for interpreting the values, such as

However I have been unsuccesful in decoding a value with Python

Example value: '\x04\x00\x01\x00\x05\xf0\x00\x00R\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|i7\x00\xc0\xa8\x016' - I know this is an A record pointing the name "barbel" to

Has anyone worked with dnsRecord values in Python?

1 Answer: 

The structure of a dnsRecord seems to be described in Microsoft's Open Specification document for DNS (MS-DNSP). Specifically for the dnsRecord it is described in section

From the above link:

DataLength (2 bytes): An unsigned binary integer containing the length, in bytes, of the Data field.

Type (2 bytes): The resource record's type. See DNS_RECORD_TYPE (section

Version (1 byte): The version number associated with the resource record attribute. The value MUST be 0x05.

Rank (1 byte): The least-significant byte of one of the RANK* flag values. See dwFlags (section

Flags (2 bytes): Not used. The value MUST be 0x0000.

Serial (4 bytes): The serial number of the SOA record of the zone containing this resource record. See DNS_RPC_RECORD_SOA (section

TtlSeconds (4 bytes): See dwTtlSeconds (section This field uses big-endian byte order.

Reserved (4 bytes): This field is reserved for future use. The value MUST be 0x00000000.

TimeStamp (4 bytes): See dwTimeStamp (section

Data (variable): The resource record's data. See DNS_RPC_RECORD_DATA (section

The challenge of course being to decode the binary dnsRecord values from AD according to the above. As several parts also have their own sections describing their values. I have not yet had to decode these values, but hopefully this information at least gets you on the right path.