Example #1
0
 def test_message_decoding(self):                    
     d = ImpactDecoder.ICMP6Decoder()
     
     msg_types = [
                  ICMP6.ICMP6.ECHO_REQUEST,
                  ICMP6.ICMP6.ECHO_REPLY,
                  ICMP6.ICMP6.PARAMETER_PROBLEM,
                  ICMP6.ICMP6.PARAMETER_PROBLEM,
                  ICMP6.ICMP6.PARAMETER_PROBLEM,
                  ICMP6.ICMP6.DESTINATION_UNREACHABLE,
                  ICMP6.ICMP6.DESTINATION_UNREACHABLE,
                  ICMP6.ICMP6.DESTINATION_UNREACHABLE,
                  ICMP6.ICMP6.DESTINATION_UNREACHABLE,
                  ICMP6.ICMP6.DESTINATION_UNREACHABLE,
                  ICMP6.ICMP6.DESTINATION_UNREACHABLE,
                  ICMP6.ICMP6.DESTINATION_UNREACHABLE,
                  ICMP6.ICMP6.TIME_EXCEEDED,
                  ICMP6.ICMP6.TIME_EXCEEDED,
                  ICMP6.ICMP6.PACKET_TOO_BIG
                  ]
     
     msg_codes = [
                 0,
                 0,                    
                 ICMP6.ICMP6.ERRONEOUS_HEADER_FIELD_ENCOUNTERED,
                 ICMP6.ICMP6.UNRECOGNIZED_NEXT_HEADER_TYPE_ENCOUNTERED,
                 ICMP6.ICMP6.UNRECOGNIZED_IPV6_OPTION_ENCOUNTERED,
                 ICMP6.ICMP6.NO_ROUTE_TO_DESTINATION,
                 ICMP6.ICMP6.ADMINISTRATIVELY_PROHIBITED,
                 ICMP6.ICMP6.BEYOND_SCOPE_OF_SOURCE_ADDRESS,
                 ICMP6.ICMP6.ADDRESS_UNREACHABLE,
                 ICMP6.ICMP6.PORT_UNREACHABLE,
                 ICMP6.ICMP6.SOURCE_ADDRESS_FAILED_INGRESS_EGRESS_POLICY,
                 ICMP6.ICMP6.REJECT_ROUTE_TO_DESTINATION,    
                 ICMP6.ICMP6.HOP_LIMIT_EXCEEDED_IN_TRANSIT,
                 ICMP6.ICMP6.FRAGMENT_REASSEMBLY_TIME_EXCEEDED,
                 0
                 ]
     
     for i in range (0, len(self.reference_data_list)):
         p = d.decode(self.reference_data_list[i])
         self.assertEqual(p.get_type(), msg_types[i], self.message_description_list[i] + " - Msg type mismatch")
         self.assertEqual(p.get_code(), msg_codes[i], self.message_description_list[i] + " - Msg code mismatch")
         
         if i in range(0, 2):
             self.assertEqual(p.get_echo_id(), 1, self.message_description_list[i] + " - ID mismatch")
             self.assertEqual(p.get_echo_sequence_number(), 2, self.message_description_list[i] + " - Sequence number mismatch")
             self.assertEqual(p.get_echo_arbitrary_data().tolist(), [0xFE, 0x56, 0x88], self.message_description_list[i] + " - Arbitrary data mismatch")
         if i in range(2, 5):
             self.assertEqual(p.get_parm_problem_pointer(), 2, self.message_description_list[i] + " - Pointer mismatch")
         if i in range(5, 15):
             self.assertEqual(p.get_originating_packet_data().tolist(), [0xFE, 0x56, 0x88], self.message_description_list[i] + " - Originating packet data mismatch")
         if i in range(14, 15):
             self.assertEqual(p.get_mtu(), 1300, self.message_description_list[i] + " - MTU mismatch")
Example #2
0
print("PING %s %d data bytes" % (dst, len(payload)))
seq_id = 0
while 1:
    # Give the ICMP packet the next ID in the sequence.
    seq_id += 1
    icmp = ICMP6.ICMP6.Echo_Request(1, seq_id, payload)

    # Have the IP packet contain the ICMP packet (along with its payload).
    ip.contains(icmp)
    ip.set_next_header(ip.child().get_ip_protocol_number())
    ip.set_payload_length(ip.child().get_size())
    icmp.calculate_checksum()

    # Send it to the target host.
    s.sendto(icmp.get_packet(), (dst, 0))

    # Wait for incoming replies.
    if s in select.select([s], [], [], 1)[0]:
        reply = s.recvfrom(2000)[0]

        # Use ImpactDecoder to reconstruct the packet hierarchy.
        rip = ImpactDecoder.ICMP6Decoder().decode(reply)

        # If the packet matches, report it to the user.
        if ICMP6.ICMP6.ECHO_REPLY == rip.get_type():
            print("%d bytes from %s: icmp_seq=%d " %
                  (rip.child().get_size() - 4, dst,
                   rip.get_echo_sequence_number()))

        time.sleep(1)