def buttonApplyClicked(self): widget = self.parent.GetCurrentTab() if widget != None and isinstance(widget, PacketData_ui): bpf = BPF() bpf.setFilterExpression(self.Ui.lineEditExpression.text()) bpf.setOriginalPacketList(widget.originalList) bpf.filterPacketList() newList = bpf.getFilteredPacketList() widget.SetPacketList(newList)
def test_PortExprFilter(self): x = BPF() packet3 = IP(dst="10.4.12.91") / TCP(dport=23) / "HelloWorld" packet4 = IP(dst="10.4.12.91") / TCP(dport=24) / "HelloWorld" packets2 = [ packet3, packet4, packet3, packet4, packet3, packet4, packet3, packet4, packet3, packet4 ] x.setOriginalPacketList(packets2) x.setFilterExpression('dst port 23') y = x.getFilteredPacketList() for packetB in zip(y): self.assertEqual(hexdump(packet3), hexdump(packetB))
def test_ComboExprFilter(self): x = BPF() packet3 = IP(dst="10.4.12.91") / TCP(dport=23) / "HelloWorld" packet4 = IP(dst="10.4.12.92") / TCP(dport=24) / "HelloWorld" packets2 = [ packet3, packet4, packet3, packet4, packet3, packet4, packet3, packet4, packet3, packet4 ] x.setOriginalPacketList(packets2) x.setFilterExpression('dst port 23 and dst host "10.4.12.92"') y = x.getFilteredPacketList() self.assertEqual(y, [])
def test_EmptyFilter(self): x = BPF() x.setFilterExpression('') packet1 = IP(dst="10.4.12.91") / ICMP() / "HelloWorld" packet2 = IP(dst="10.4.12.91") / TCP(dport=23) packets = [ packet1, packet2, packet1, packet2, packet1, packet2, packet1, packet2, packet1, packet2 ] x.setOriginalPacketList(packets) x.filterPacketList() y = x.getFilteredPacketList() for (packetA, packetB) in zip(packets, y): self.assertEqual(hexdump(packetA), hexdump(packetB))