| 36 | |
| 37 | |
| 38 | class DNSQuery: |
| 39 | def __init__(self, data): |
| 40 | self.data = data |
| 41 | self.domain = b'' |
| 42 | tipo = (data[2] >> 3) & 15 # Opcode bits |
| 43 | if tipo == 0: # Standard query |
| 44 | ini = 12 |
| 45 | lon = data[ini] |
| 46 | while lon != 0: |
| 47 | self.domain += data[ini + 1:ini + lon + 1] + b'.' |
| 48 | ini += lon + 1 # you can implement CNAME and PTR |
| 49 | lon = data[ini] |
| 50 | self.type = data[ini:][1:3] |
| 51 | else: |
| 52 | self.type = data[-4:-2] |
| 53 | |
| 54 | # Because python doesn't have native ENUM in 2.7: |
| 55 | # https://en.wikipedia.org/wiki/List_of_DNS_record_types |