示例#1
0
 def test_parses_valid_stream(self):
     stream = io.BytesIO(TESTDATA)
     pcap = PCAP(stream)
     header = pcap.global_header
     self.assertThat(header, Equals((2712847316, 2, 4, 0, 0, 64, 1)))
     pkt1 = pcap.read()
     self.assertThat(pkt1[0], Equals((1467058714, 931534, 60, 60)))
     self.assertThat(
         pkt1[1],
         Equals(
             b"\xff\xff\xff\xff\xff\xff\x00$\xa5\xaf$\x85\x08\x06\x00\x01\x08"
             b"\x00\x06\x04\x00\x01\x00$\xa5\xaf$\x85\xac\x10*\x01\x00\x00\x00"
             b"\x00\x00\x00\xac\x10*\xa7\x00\x00\x00\x00\x00\x00\x00\x00\x00"
             b"\x00\x00\x00\x00\x00\x00\x00\x00\x00"),
     )
     pkt2 = pcap.read()
     self.assertThat(pkt2[0], Equals((1467058715, 380619, 60, 60)))
     self.assertThat(
         pkt2[1],
         Equals(
             b"\x80\xfa[\x0cFN\x00$\xa5\xaf$\x85\x08\x06\x00\x01\x08\x00\x06"
             b"\x04\x00\x01\x00$\xa5\xaf$\x85\xac\x10*\x01\x00\x00\x00\x00\x00"
             b"\x00\xac\x10*m\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
             b"\x00\x00\x00\x00\x00\x00"),
     )
示例#2
0
 def test_raises_EOFError_for_end_of_stream(self):
     stream = io.BytesIO(TESTDATA)
     pcap = PCAP(stream)
     pcap.read()
     pcap.read()
     with ExpectedException(EOFError, "End of PCAP stream."):
         pcap.read()
示例#3
0
 def test_raises_PCAPError_for_invalid_packet(self):
     stream = io.BytesIO(TESTDATA_INVALID_PACKET)
     pcap = PCAP(stream)
     header = pcap.global_header
     self.assertThat(header, Equals((2712847316, 2, 4, 0, 0, 64, 1)))
     with ExpectedException(
             PCAPError, "Unexpected end of PCAP stream: invalid packet."):
         pcap.read()