def parse_payload(self, payload): try: packet = Packet.parse(payload) except: print('Unable to parse packet') return self.print_packet(packet)
def send(self, server, tcp=False, questions=[]): packet = Packet(int(random.random() * 1000), questions=questions) payload = bytes(packet) if tcp: sock = zokket.TCPSocket(self) sock.connect(server, 53) sock.read_until_length = 2 sock.buffer_type = None self.payload = payload else: sock = zokket.UDPSocket(self) sock.bind() sock.send(server, 53, payload)
def test_packet(self): payload = b'l\x96\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x04test\x03com\x00\x00\x01\x00\x01' packet = Packet.parse(payload) self.assertEqual(packet.__bytes__(), payload)