def __str__(self):
     return str(self.opcode) + ': ' + hex(self.sender_mac) + ' / ' + int_to_ip(self.sender_ip) + \
         ' -> ' + hex(self.target_mac) + ' / ' + int_to_ip(self.target_ip)
Exemple #2
0
 def recive(self, ip_packet):
     icmp_packet = ICMPPacket()
     icmp_packet.decode(ip_packet.payload)
     print 'icmp packet from %s to %s' % (int_to_ip(ip_packet.source), int_to_ip(ip_packet.destination))
Exemple #3
0
 def recive(self, ip_packet):
     print 'udp packet from %s to %s' % (int_to_ip(ip_packet.source), int_to_ip(ip_packet.destination))
Exemple #4
0
 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)