Guest User

Untitled

a guest
Jun 25th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. class DnsPacket(BigEndianStructure):
  2. """ Class representative to DNS header.
  3. This class handle a bytes buffer in ctypes field mode """
  4.  
  5. def __new__(cls, buffer):
  6. return cls.from_buffer_copy(buffer)
  7.  
  8. _fields_ = [('identification', c_uint, 16),
  9. ('query_type', c_uint, 1),
  10. ('optional_code', c_uint, 4),
  11. ('authoritative_answer', c_uint, 1),
  12. ('truncation', c_uint, 1),
  13. ('recursion_desired', c_uint, 1),
  14. ('recursion_available', c_uint, 1),
  15. ('reserved_for_future', c_uint, 3),
  16. ('response_code', c_uint, 4),
  17. ('question_count', c_uint, 16),
  18. ('answer_count', c_uint, 16),
  19. ('nameserver_count', c_uint, 16),
  20. ('aditional_count', c_uint, 16)]
  21.  
  22. 1 1 1 1 1 1
  23. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
  24. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  25. | |
  26. / QNAME /
  27. / /
  28. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  29. | QTYPE |
  30. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  31. | QCLASS |
  32. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  33.  
  34. class QuestionSection(BigEndianStructure):
  35. _fields_ = [('size', c_uint), # Primeiro octeto contendo o número de caracteres na label.
  36. ('name', size)] # Label em sí
  37.  
  38. def get_domain_name(self, data):
  39. array_data = bytearray(data[sizeof(self):])
  40. expected_lenght = array_data.pop(0)
  41. nameserver = ''
  42. while expected_lenght is not 0:
  43. for _ in range(expected_lenght):
  44. nameserver += chr(array_data.pop(0))
  45. expected_lenght = array_data.pop(0)
  46. if expected_lenght is not 0:
  47. nameserver += '.'
  48. return nameserver
Add Comment
Please, Sign In to add comment