Exemple #1
0
 def __init__(self, program_string):
     """
     Create a filter using the BPF command syntax. To learn more,
     consult 'man pcap-filter'.
     :param program_string: The textual definition of the filter. Examples:
     'vlan 1000'
     'vlan 1000 and ip src host 10.10.10.10'
     """
     self._program_string = program_string
     self._bpf = pcapy.BPFProgram(program_string)
    def testBPFFilter(self):
        """
        #3 test offline BPFFilter
        """
        r = pcapy.open_offline(TestPcapy._96PINGS)
        bpf = pcapy.BPFProgram("ip dst host 192.168.1.1")

        hdr, pkt = r.next()
        while hdr is not None:
            f = bpf.filter(pkt)
            self.assertNotEqual(f, 0)
            hdr, pkt = r.next()