def test_received_ip_packet(self):
     self.analyze_packets("h1", lambda: self.net.pingAll())
     packet = Packet()
     packet.ip_src = "192.168.0.1"
     packet.ip_dst = "192.168.0.2"
     self.assertReceivedPacket(packet, "Received ip packet")
     packet1 = Packet()
     packet1.ip_src = "192.168.0.254"
     packet1.ip_dst = "192.168.0.2"
     self.assertNotReceivedPacket(packet1, "Not received packet from unknown ip.")
Exemplo n.º 2
0
 def test_received_ip_packet(self):
     self.analyze_packets("h1", lambda: self.net.pingAll())
     packet = Packet()
     packet.ip_src = "192.168.0.1"
     packet.ip_dst = "192.168.0.2"
     self.assertReceivedPacket(packet, "Received ip packet")
     packet1 = Packet()
     packet1.ip_src = "192.168.0.254"
     packet1.ip_dst = "192.168.0.2"
     self.assertNotReceivedPacket(packet1,
                                  "Not received packet from unknown ip.")
    def test_timestamps(self):
        self.analyze_packets(["h1", "h3"], lambda: self.net.pingAll())
        packet_1_to_2 = Packet()
        packet_1_to_2.ip_src = "192.168.0.1"
        packet_1_to_2.ip_dst = "192.168.0.2"

        packet_3_to_4 = Packet()
        packet_3_to_4.ip_src = "192.168.0.3"
        packet_3_to_4.ip_dst = "192.168.0.4"
        time_1_to_2 = self.get_all_packets(packet_1_to_2, "h1")[0].time_stamp
        time_3_to_4 = self.get_all_packets(packet_3_to_4, "h3")[0].time_stamp
        self.assertTrue(time_3_to_4 > time_1_to_2, "Timestamp ordering ok. Ping from h1 to h2 is sent first.")
    def test_timestamps(self):
        self.analyze_packets(["h1", "h3"], lambda: self.net.pingAll())
        packet_1_to_2 = Packet()
        packet_1_to_2.ip_src = "192.168.0.1"
        packet_1_to_2.ip_dst = "192.168.0.2"

        packet_3_to_4 = Packet()
        packet_3_to_4.ip_src = "192.168.0.3"
        packet_3_to_4.ip_dst = "192.168.0.4"
        time_1_to_2 = self.get_all_packets(packet_1_to_2, "h1")[0].time_stamp
        time_3_to_4 = self.get_all_packets(packet_3_to_4, "h3")[0].time_stamp
        self.assertTrue(
            time_3_to_4 > time_1_to_2,
            "Timestamp ordering ok. Ping from h1 to h2 is sent first.")
    def test_send_icmp(self):

        icmp_cont = dpkt.icmp.ICMP.Echo()
        icmp_cont.data = 'icmp echo'
        icmp_cont.seq = random.randint(0, 65535)
        icmp_cont.id = random.randint(0, 65535)

        icmp_packet = dpkt.icmp.ICMP()
        icmp_packet.type = dpkt.icmp.ICMP_ECHO
        icmp_packet.data = icmp_cont

        self.analyze_packets("h2", lambda: self.send_ip4_packet("h1", "192.168.0.2", dpkt.ip.IP_PROTO_ICMP, str(icmp_packet)))
        packet = Packet()
        packet.ip_src = "192.168.0.1"
        packet.ip_dst = "192.168.0.2"
        self.assertReceivedPacket(packet, "Received sent icmp packet", "h2")
    def test_tcp(self):
        # start netcat server
        self.execCmd("h2", "nc -l 12345 &")
        pid = self.net.get("h2").lastPid

        # send packets
        self.analyze_packets("h1", lambda: self.execCmd("h1", "echo 'TEST' | nc 192.168.0.2 12345"))

        # stop netcat server
        self.execCmd("h2", "kill " + str(pid))

        # analyze packets
        packet = Packet()
        packet.ip_src = "192.168.0.1"
        packet.ip_dst = "192.168.0.2"
        packet.tcp_dst_port = 12345
        self.assertReceivedPacket(packet, "TCP Packet Received")
Exemplo n.º 7
0
    def test_send_icmp(self):

        icmp_cont = dpkt.icmp.ICMP.Echo()
        icmp_cont.data = 'icmp echo'
        icmp_cont.seq = random.randint(0, 65535)
        icmp_cont.id = random.randint(0, 65535)

        icmp_packet = dpkt.icmp.ICMP()
        icmp_packet.type = dpkt.icmp.ICMP_ECHO
        icmp_packet.data = icmp_cont

        self.analyze_packets(
            "h2", lambda: self.send_ip4_packet(
                "h1", "192.168.0.2", dpkt.ip.IP_PROTO_ICMP, str(icmp_packet)))
        packet = Packet()
        packet.ip_src = "192.168.0.1"
        packet.ip_dst = "192.168.0.2"
        self.assertReceivedPacket(packet, "Received sent icmp packet", "h2")
Exemplo n.º 8
0
    def test_tcp(self):
        # start netcat server
        self.execCmd("h2", "nc -l 12345 &")
        pid = self.net.get("h2").lastPid

        # send packets
        self.analyze_packets(
            ["h1", "h2"],
            lambda: self.execCmd("h1", "echo 'TEST' | nc 192.168.0.2 12345"))

        # stop netcat server
        self.execCmd("h2", "kill " + str(pid))

        packet = Packet()
        packet.ip_src = "192.168.0.1"
        packet.ip_dst = "192.168.0.2"
        packet.tcp_dst_port = 12345
        self.assertReceivedPacket(packet, "TCP Packet Received on h1", "h1")
        self.assertReceivedPacket(packet, "TCP Packet Received on h2", "h2")