def recive(self, ethernet_frame): arp_packet = ARPPacket() arp_packet.decode(ethernet_frame.payload) print 'arp packet from %s to %s (%s)' % (hex(ethernet_frame.source), hex(ethernet_frame.destination), int_to_ip(arp_packet.target_ip)) if arp_packet.target_ip == ip_address: arp_response = ARPPacket() arp_response.hw_type = 1 arp_response.proto_type = 0x800 arp_response.hw_size = 6 arp_response.proto_size = 4 arp_response.opcode = 2 arp_response.sender_mac = mac_address arp_response.sender_ip = ip_address arp_response.target_mac = arp_packet.sender_mac arp_response.target_ip = arp_packet.sender_ip ethernet_handler.send(arp_response.encode(), ARP_PROTOCOL, arp_packet.sender_mac)